matthewst Posted March 19, 2008 Share Posted March 19, 2008 a 1 a 2 a 3 b 1 a 4 Right now it echoes like this: a 4 I need it to echo like this: a 1,2,3,4 Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 19, 2008 Share Posted March 19, 2008 You have to explain things better, and show us some code. Your post doesn't make sense. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 19, 2008 Share Posted March 19, 2008 Provide your table structure, what you want to display, and which version of MySQL you are using. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 20, 2008 Share Posted March 20, 2008 [pre] x | y ---+--- a | 1 a | 2 a | 3 b | 1 a | 4 [/pre] SELECT x, GROUP_CONCAT(y SEPARATOR ', ') as ylist FROM mytablename GROUP BY x Quote Link to comment Share on other sites More sharing options...
matthewst Posted March 20, 2008 Author Share Posted March 20, 2008 Sorry barand I'm not that smart. I only need to display the "1,2,3's" (dates) for this query, not the a's and b's. The problem I'm having is I need to display dates from records with the same $id. Example table: id | date a | 1 a | 1 a | 2 b | 7 a | 3 I need displayed like this: (for the a's) 1,1,2,3 $query_dates="SELECT action FROM table_1 WHERE id=$id AND action=208"; $result_dates=mysql_query($query_dates); while ($row_dates = mysql_fetch_assoc($result_dates)) { $action = $row_dates['action']; } if ($action){ $Get_Copy = mysql_query("SELECT * FROM tabel_2 WHERE order_id='$id'", $db_link); while($pics = mysql_fetch_array($Get_Copy)) { $id = $pics['ord_id']; $des_date = $pics['ord_date']; } if ($des_date != ""){ $des_date = substr($des_date, 4, 2).'/'.substr($des_date, 6, 2).'/'.substr($des_date, 0, 4); } echo "<td align='center' valign='top' width='60'><font size='-2'>$des_date<br></font></td>"; $des_date = ""; } Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 20, 2008 Share Posted March 20, 2008 Barand's solution will work for what you want to do. SELECT GROUP_CONCAT(date SEPARATOR ', ') as date_list FROM example_table GROUP BY id Quote Link to comment Share on other sites More sharing options...
matthewst Posted March 21, 2008 Author Share Posted March 21, 2008 I just had to move some stuff around. Thanks Everyone! $query_dates="SELECT action FROM table_1 WHERE id=$id AND action=208"; $result_dates=mysql_query($query_dates); while ($row_dates = mysql_fetch_assoc($result_dates)) { $action = $row_dates['action']; } if ($action){ $Get_Copy = mysql_query("SELECT * FROM tabel_2 WHERE order_id='$id'", $db_link); while($pics = mysql_fetch_array($Get_Copy)) { $id = $pics['ord_id']; $des_date = $pics['ord_date']; if ($des_date != ""){ $des_date = substr($des_date, 4, 2).'/'.substr($des_date, 6, 2).'/'.substr($des_date, 0, 4); } echo "<td align='center' valign='top' width='60'><font size='-2'>$des_date<br></font></td>"; $des_date = ""; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.