echo in variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Conor
Forum Newbie
Posts: 4
Joined: Sun Feb 13, 2005 1:55 pm

echo in variable

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Just do this

Code: Select all

//$dirlist is where images are - echo username

$dirlist = $row_rsUserphotos['username']."/";
Conor
Forum Newbie
Posts: 4
Joined: Sun Feb 13, 2005 1:55 pm

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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. :)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Padding strings should be with the str_pad command
http://www.php.net/manual/en/function.str-pad.php.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

8O simple overlook on my part. *banging his head against wall* :)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sprintf()/printf() also work pretty good at that too.
Post Reply