Jump to content

Php mysql statement


wipeskim

Recommended Posts

Hi,

I am doing a script with php and mysql wich i want to list the orders details such as session_id, date, username and id.

To do this i used select distinct session_id from orders

cause i have 2 orders with the same session_id but i also want to list the username, date and id.

Since i used to distinct only the session_id it will only print on the screen the session id's.

I tryed "select Distinct session_id, username, date,id from orders" but in this case since some fields has diferent values even having the same session_id it will list all the results on the table.

Is there anyway of using the select statement to select all the fields and distinguish the session_id so that i can avoid duplicated session id's on the results?

If someone can help me i appreciate

Many thanks to all
Link to comment
Share on other sites

Do you mean
[code]<?php
$sql = "select session_id, username, date,id
from orders
order by session_id";
$res = mysql_query($sql) or die(mysql_error());

$last_sid = '';
echo '<table border="1">';
while (list($sid, $usr, $dt, $id) = mysql_fetch_row($res)) {
    $sess = ($sid==$last_sid) ? '&nbsp;' : $sid;
    echo "<tr><td>$sess</td>
    <td>$usr</td>
    <td>$dt</td>
    <td>$id</td></tr>\n";
    $last_sid = $sid;
}
echo '</table>';
?>
[/code]
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.