EN - Bugreportsc_randompic.php


26.03.2010, 11:30 - webdede - webSPELL newbie - 30 Posts
Hi.

I was reading the sc_randompic.php file to adapt if for a sc_lastpic.php ( a new file ) and I think there is a littke mistake of coding in this file :

Code:
1.
while (false !== ($file = readdir($picdir)))


I know the "==" or the "!=" but what is "!==" ?

I think it was "!=" instead. So maybe php ignore the test and it continue to work but I think if you want the test to be done you must replace the "!==" condition by the a "!=", exact ?




By the way I was trying to have the lastpic of the thumbs from the galery instead of a randompic from the user pics.

So I have replace :
$picpath = './images/userpics/';
by
$picpath = './images/gallery/thumb/';

and
$the_pic = $pic_array[rand(0,($anz-1))];
by
$the_pic = $pic_array[$anz-1];

but it doesnt display me the latest one but another one :/ Any idea ?
 
26.03.2010, 11:56 - blue.tiger - Administrator - 3188 Posts
http://www.php.net/man....operators.comparison.php
Operators with three characters are also checking for the type of the comparison parameters.

If you want to select the latest galery picture, you shouldn't use this way. Select the latest picture by using an mysql query instead:
Code:
1.
$last_picture=mysql_fetch_assoc(safe_query("SELECT picID FROM ".PREFIX."gallery_pictures ORDER BY picID DESC LIMIT 0,1"));

 
26.03.2010, 12:02 - webdede - webSPELL newbie - 30 Posts
Oh ok sorry I didnt know this operator ! I'm not a pro in web coding zunge raus

For the code you mention to get the latest picture, ok, I will try your way.

But what makes my way to fail ? I mean if I have understood the code correctly, the code list all the pics in a table and then pick a random one between [0;size-1] of the table. So I was quite sure that if I was replacing the random(0;size-1) by only (size-1) I will get the latest one, but it looks like it's not the case, indeed.

So actually I was even thinking that the random function was not picking among the total ammount of picture given that (size-1) doesnt look like to refer to the latest one.

I must be wrong somewhere ^^
 
26.03.2010, 13:08 - webdede - webSPELL newbie - 30 Posts
Hm I have tried with your mysql request and in $last_picture I have "Array" returned. No pic ID.
 
26.03.2010, 13:42 - webdede - webSPELL newbie - 30 Posts
Here is my code :

Code:
1.
2.
3.
4.
5.
6.
7.
8.
$picpath = './images/gallery/thumb/';
$last_pic = mysql_fetch_assoc(safe_query("SELECT picID FROM ".PREFIX."gallery_pictures ORDER BY picID DESC LIMIT 0,1"));
$last_picID = str_replace(strrchr($last_pic,'.'),'',$last_pic);

$picurl = $picpath.$last_pic;

eval ("\$sc_lastpic = \"".gettemplate("sc_lastpic")."\";");
echo $sc_lastpic;


Any idea what could be wrong ?