Jump to content

Treating array as string?


magicmoose

Recommended Posts

Hi,

I'm trying to display an unset number of images on a page, using an array to hold things like the directory and filenames etc.  However, instead of echoing the values of each image, the single letter in the $key position is being echoed.

 

For example "uploads" 2 gives the letter L.

 

I've had this working on a separate page, but the code looks exactly the same.  Can anyone point me in the right direction?  Thanks.

 


$directories = array();
$filenames = array();
$locations = array();
if($imageConn->num_rows()>0){

while($imageConn->moveNext()) {

$directories[] = $imageConn->getField("directory");
$filenames[] = $imageConn->getField("filename");
$locations[] = $imageConn->getField("location");


  }

}  

foreach ($directories as $key => $directory) {

  echo $directory[$key]."<br />;
  echo $filename[$key]."<br />;
  echo $location[$key]."<br />;
       
}

Link to comment
Share on other sites

Hmm not sure if this matters, but you should close your <br/> tags

 

echo $directory[$key]."<br />";
  echo $filename[$key]."<br />";
  echo $location[$key]."<br />";

 

Also what happens when you run

 

echo '<pre>';
print_r($directories);
echo '</pre>';

Link to comment
Share on other sites

Hmm I think you might be passing a wrong variable somewhere. ie. Where is:

$directory[]

$filename[]

$location[]

coming from? Should they not be:

$directories[]

$filenames[]

$locations[]

 

I actually had this problem sometime ago, and it was a silly error in passing the wrong variable ("doh!") http://www.phpfreaks.com/forums/index.php/topic,252458.msg1185666.html#msg1185666

 

Try to echo out (outside the loop) the exact phrase you want. so maybe

 

echo $directories[0].$filenames[0].$locations[0];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.