Jump to content

GROUP BY/ORDER BY


mdub2112

Recommended Posts

The end result I'm looking for is:

Client's Name
      Record1
      Record2
      Record3
Client's Name
      Record1
      Record2
      Record3


The query I'm using is

[code=php:0]
  $uploads_sql = "select *
  from user_permissions, uploads, clients
  where user_permissions.username = '{$_SESSION['auth_user']}'
  and uploads.client = clients.code  
  and clients.code = user_permissions.company";
 
  $uploads_result = $handle->query($uploads_sql);
[/code]

[b]The while loop I'm using is[/b]

[code=php:0]
  while ($uploads = $uploads_result->fetch_assoc())
{
echo '<tr><td>';
echo $uploads['client'];
echo '</td></tr>';
echo '<tr><td>';
echo $uploads['comments'];
echo '</td></tr>';
echo '<tr><td>';
echo 'Download: '."<a href=download.php?id={$uploads['id']}>{$uploads['title']}<br /></a>";
echo '[<a href="delete_record.php?file='.$uploads['id'].'">Delete Record</a>] ';
echo '</td></tr>';
}
[/code]

With that query and code I get:

Client's Name
Record1
Client's Name
Record2
Client's Name
Record3


If I change the query to include GROUP BY client, it only shows one record.  How can I go about getting the end result I'm looking for?
Sort of a noob here so...

Hopefully I've given the info needed to see what I'm doing.
Link to comment
https://forums.phpfreaks.com/topic/30368-group-byorder-by/
Share on other sites

Looks like DISTINCT is going to do exactly what I want.
THANKS

Only problem I have now LOL is trying to figure out how to resolve the
[color=red]Trying to get property of non-object in /var/www/html/blablabla on line 34[/color] message I'm getting
(line 34 = [color=purple]echo $user['fullname'].' You have access to ' . $uploads_result->num_rows . ' records.'[/color])
Link to comment
https://forums.phpfreaks.com/topic/30368-group-byorder-by/#findComment-139928
Share on other sites

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.