JChilds Posted January 12, 2009 Share Posted January 12, 2009 I am trying to find all people in a particular category. I then want to group by name. All people have more than one entry in each category. I want to print out every person in this category, and each entry they have. eg/ Bill - 23, 45, 34, 56 Bob - 77, 43, 35, 98 I am getting the array the following way, but am unsure how to extract the data after this. $sql = mysql_query("SELECT * FROM $table WHERE category LIKE '$term' GROUP BY name"); Link to comment https://forums.phpfreaks.com/topic/140428-multidimensional-array-help/ Share on other sites More sharing options...
.josh Posted January 12, 2009 Share Posted January 12, 2009 http://www.phpfreaks.com/tutorial/php-basic-database-handling Link to comment https://forums.phpfreaks.com/topic/140428-multidimensional-array-help/#findComment-734968 Share on other sites More sharing options...
JChilds Posted January 12, 2009 Author Share Posted January 12, 2009 Ok, maybe I made myself seem a little stupid. I would usually use while(($row = mysql_fetch_array($sql))){ echo $row['blah'] } But this only gets me the first entry in each 'sub array' Link to comment https://forums.phpfreaks.com/topic/140428-multidimensional-array-help/#findComment-734971 Share on other sites More sharing options...
.josh Posted January 12, 2009 Share Posted January 12, 2009 $row will be an array of each column for the current row you are on. So echo $row['blah']; would echo out the column named 'blah'. So for example, if you have the following db table: sometable id name 1 Bob 2 Jan 3 James you can for instance, echo out each column in the current row like this: $sql = "select * from sometable"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { echo "id: {$row['id']} name: {$row['name']} <br/>"; } This would be the output: id: 1 name: Bob id: 2 name: Jan id: 3 name: James So basically you would do $row['columnname'] if you are using _fetch_array or _fetch_assoc and you would refer to them individually, or you can loop through each one, inside your while loop: while ($row = mysql_fetch_assoc($result)) { foreach ($row as $column => $value) { echo "$column : $value <br/>"; } echo "<br/>"; } Link to comment https://forums.phpfreaks.com/topic/140428-multidimensional-array-help/#findComment-734989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.