Jump to content


Php mysql statement

  • Please log in to reply
1 reply to this topic

#1 wipeskim

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 July 2006 - 04:59 PM


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

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 23 July 2006 - 05:18 PM

Do you mean
$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>
     $last_sid = $sid;
echo '</table>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users