suttercain Posted November 20, 2008 Share Posted November 20, 2008 <?php if (isset($_GET['q'])) { require('../vdb/includes/connection.php'); $q=$_GET["q"]; echo $q; $statement = "SELECT engine_family_name FROM eo_engine_family WHERE engine_family_name LIKE '".$q."%'"; $results = mysql_query($statement) or die(mysql_error()); while($row=mysql_fetch_assoc($results)) { $items[]=$row; } //print_r($items); foreach ($items as $key => $value) { echo "Value: $value<br />\n"; } } ?> When I use the print_r on the items, I can see the array keys and values, but trying to loop through the array with the foreach is just outing putting Array over and over. Quote Link to comment https://forums.phpfreaks.com/topic/133533-solved-basic-foreach-and-displaying-the-array-values-im-too-tired-cant-figure-it/ Share on other sites More sharing options...
premiso Posted November 20, 2008 Share Posted November 20, 2008 Because $row is an array. <?php if (isset($_GET['q'])) { require('../vdb/includes/connection.php'); $q=$_GET["q"]; echo $q; $statement = "SELECT engine_family_name FROM eo_engine_family WHERE engine_family_name LIKE '".$q."%'"; $results = mysql_query($statement) or die(mysql_error()); while($row=mysql_fetch_assoc($results)) { $items[]=$row; } //print_r($items); foreach ($items as $value) { foreach ($value as $key => $newval) { echo "Value: $newval<br />\n"; } } } ?> Should give you what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/133533-solved-basic-foreach-and-displaying-the-array-values-im-too-tired-cant-figure-it/#findComment-694554 Share on other sites More sharing options...
suttercain Posted November 20, 2008 Author Share Posted November 20, 2008 Doh! Thank you kindly. Quote Link to comment https://forums.phpfreaks.com/topic/133533-solved-basic-foreach-and-displaying-the-array-values-im-too-tired-cant-figure-it/#findComment-694557 Share on other sites More sharing options...
rhodesa Posted November 20, 2008 Share Posted November 20, 2008 or move it inside the while loop: <?php if (isset($_GET['q'])) { require('../vdb/includes/connection.php'); $q=$_GET["q"]; echo $q; $statement = "SELECT engine_family_name FROM eo_engine_family WHERE engine_family_name LIKE '".$q."%'"; $results = mysql_query($statement) or die(mysql_error()); while($row=mysql_fetch_assoc($results)) { foreach ($row as $key=>$value) { echo "$key: $value<br />\n"; } echo "<hr>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/133533-solved-basic-foreach-and-displaying-the-array-values-im-too-tired-cant-figure-it/#findComment-694560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.