PHP Array Help Please

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
cristobal
Forum Newbie
Posts: 1
Joined: Wed Sep 10, 2008 8:07 pm

PHP Array Help Please

Post by cristobal »

I am a newbie to PHP for sure. I need some advice though. I am attempting to tweak an existing PHP script I have.

The is an array called $row that has all the value that was pulled from a database.

I want to take the values $row [ 'propertyphoto1' ] , $row [ 'propertyphoto2' ], $row [ 'propertyphoto3' ] and so forth up to propertyphoto 8 and put them in a different array in which I will use that array to mesh with a image rotator.

Here is the code I am working with:
?php if ( ! $row [ 'propertyphoto1' ] )
{
?><img src="<?php echo $ImageURL; ?>nopropertyimage.jpg" border="0" align="left" hspace="10" height="150" width="200"><?php
}
else
{
?><?
$pic = array("echo $row ['propertyphoto2']", "echo $row ['propertyphoto3']", "echo $row ['propertyphoto1']" );

?>
<? echo $pic[2]; ?>

I have the above echo $pic[2]; just to see if I am actually storing the array correctly ie., the propertyphoto values.

But all it does it print out

echo Array ['propertyphoto1']

instead the actual value of the propertyphoto1 which is something like imagename.jpg.

Can anyone point me to the right direction as to what I am doing wrong??

Thanks for your help

Chris
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: PHP Array Help Please

Post by Ziq »

Look at this line:

Code: Select all

$pic = array("echo $row ['propertyphoto2']", "echo $row ['propertyphoto3']", "echo $row ['propertyphoto1']" );
You have error in syntax "echo $row ['propertyphoto1']" (needless space). You should use something like this:

Code: Select all

 
"echo {$row['propertyphoto1']}"
//or
"echo ".$row['propertyphoto1']
//or
'echo '.$row['propertyphoto1']
//  Read manual
 
Post Reply