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
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
Share on other sites

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.