magicmoose Posted June 29, 2009 Share Posted June 29, 2009 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 More sharing options...
Cosizzle Posted June 29, 2009 Share Posted June 29, 2009 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 https://forums.phpfreaks.com/topic/164127-treating-array-as-string/#findComment-865829 Share on other sites More sharing options...
magicmoose Posted June 29, 2009 Author Share Posted June 29, 2009 Oops, sorry for typo. Your code gives me the following: Array ( [0] => uploads/ [1] => uploads/ ) Link to comment https://forums.phpfreaks.com/topic/164127-treating-array-as-string/#findComment-865835 Share on other sites More sharing options...
Cosizzle Posted June 29, 2009 Share Posted June 29, 2009 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 https://forums.phpfreaks.com/topic/164127-treating-array-as-string/#findComment-865848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.