Jump to content

Recommended Posts

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

$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/>";
}

 

 

 

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.