Page 1 of 1

echo in variable

Posted: Tue Mar 29, 2005 1:46 am
by Conor
Hey

I have a gallery on my website, in which users can log in and see their photos. I'm trying to run a code that shows the images of a directory (ie. their directory). At the minute I have:

Code: Select all

//$dirlist is where images are
$dirlist = "cmclaughlin/";
However, this would mean it would be cmclaughlin's directory for all users. I have a recordset, with the username column in it (which is always same as directory name). What i want is something like this:

Code: Select all

//$dirlist is where images are - echo username
$dirlist = ("echo $row_rsUserphotos['username']");
But with the above, I keep getting parsing errors.

Any help would be appreciated!


Conor

Posted: Tue Mar 29, 2005 2:05 am
by JayBird
Just do this

Code: Select all

//$dirlist is where images are - echo username

$dirlist = $row_rsUserphotos['username']."/";

Posted: Tue Mar 29, 2005 7:16 am
by Conor
Thanks - that's better!

One more quick question. All the image files are saved as 001, 002, 003, 004 etc. I want there to be a "prev"/"next" link, and am adding/subtracting one from the URL variable

Code: Select all

//Set variables for navigation. Previous Next
$next = $fileno+1;
$prev = $fileno-1;
The only thing is - say the current URL v. is 005. When you add 1, it goes to 6 instead of 006. The same is with 069 -> 70 etc. Obviously, I need it to be all three figures to match the file names.



Any ideas?

Conor

Posted: Tue Mar 29, 2005 7:29 am
by n00b Saibot

Code: Select all

function fmtNum($num)
{
if ($num>0 && $num<10) return '00'.$num;
if ($num>9 && $num<100) return '0'.$num;
return $num;
}
run every number thru this function. :)

Posted: Tue Mar 29, 2005 8:04 am
by CoderGoblin
Padding strings should be with the str_pad command
http://www.php.net/manual/en/function.str-pad.php.

Posted: Tue Mar 29, 2005 8:23 am
by n00b Saibot
8O simple overlook on my part. *banging his head against wall* :)

Posted: Tue Mar 29, 2005 8:29 am
by CoderGoblin
n00b Saibot... No Problem we all do it... You could also use sprintf which I believe is faster.

I would still use str_pad as it tends to make the code more readable/obvious and in this instance I doubt if the time difference is really essential and/or noticeable.

Posted: Tue Mar 29, 2005 8:49 am
by feyd
sprintf()/printf() also work pretty good at that too.