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
https://forums.phpfreaks.com/topic/164127-treating-array-as-string/
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>';

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];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.