Forum Moderators: coopster

Message Too Old, No Replies

Simple variable syntax?

Looking for more elegant solution

         

Noisehag

9:10 pm on May 13, 2008 (gmt 0)

10+ Year Member



Hello all. I'm getting my feet wet in PHP and am stumped on how to achieve something a little more simple than what I have going on right now. I want to create a variable that contains the full path of an image where the image name is being created from a unique ID number pulled from the database.

Here is my current setup which works fine. (Let us say the current row ID value equals 20)

$fpath = "E:\\images\\";
$fname = $row['ID'];
$fext = ".jpg";

$file = "$fpath$fname$fext";

When all is said and done, I want the value of the variable $file to equal "E:\images\20.jpg"

I know there is a more simple and elegant way of doing it, but I couldn't figure out the correct syntax.

Thanks in advance! :)

eelixduppy

10:44 pm on May 13, 2008 (gmt 0)



You can just use simple string concatenation to achieve what you want here. It would look something along these lines:

$file = 'E:\\images\\' . $row['ID'] . '.jpg';

Refer to the string documentation for more information: [us.php.net...]

Happy learning :)

Noisehag

10:57 pm on May 13, 2008 (gmt 0)

10+ Year Member



Very nice, thank you for that eelixduppy! I think the problem I was having before was the use of double quotes as opposed to single. It's so simple, I'm blushing. haha

Thanks for the link, I'll do some reading. ;)