schone Posted May 20, 2006 Share Posted May 20, 2006 Hi all!I have the following table:[b]recovery_interventions[/b]- id- player_id- date- qu_id- valueHere is my code:[code]<?php $result = mysql_query("SELECT player_id, DATE_FORMAT(date, '%d/%m/%y') AS new_date, qu_id, value FROM reports_interventions ORDER BY player_id, date DESC"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $player_id = $row['player_id']; echo $player_id; $result_num = mysql_query("SELECT player_id FROM reports_interventions WHERE player_id = $player_id"); $num_rows = mysql_num_rows($result_num); for($i=0; $i < $num_rows; $i++) { echo "<br>"; echo $row['new_date']; echo "<br>"; echo $row['qu_id']; echo "<br>"; echo $row['value']; echo "<p>"; } }?>[/code]Now [b]MY PROBLEM[/b] :)What Im trying to do is display a player_id and then its date, qu_id and value. There is many dates, qu_ids and values associated with individual player_id's.For example I would like my output to look like this:player_id : 4date : 10/10/06qu_id : 4value : 2date : 10/10/06qu_id : 6value : 3date : 10/10/06qu_id : 9value : 1[b]At the moment its displaying:[/b]player_id : 4date : 10/10/06qu_id : 4value : 2date : 10/10/06qu_id : 4value : 2player_id : 4date : 10/10/06qu_id : 6value : 3date : 10/10/06qu_id : 6value : 3player_id : 4date : 10/10/06qu_id : 9value : 1date : 10/10/06qu_id : 9value : 1I have wrecked my brain and the mysql.net and php.net manuals but get no where! Please help! Quote Link to comment https://forums.phpfreaks.com/topic/10066-displaying-recordshelp/ Share on other sites More sharing options...
kenrbnsn Posted May 20, 2006 Share Posted May 20, 2006 Your second query and loop are meaningless, remove them. You might be able to use the GROUP BY clause in your first query, but I'm not sure.You could also try:[code]<?php $result = mysql_query("SELECT player_id, DATE_FORMAT(date, '%d/%m/%y') AS new_date, qu_id, value FROM reports_interventions ORDER BY player_id, date DESC"); $hold_id = ''; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($hold_id != $row['player_id']) { echo $row['player_id']; $hold_id = $row['player_id'] } echo "<br>"; echo $row['new_date']; echo "<br>"; echo $row['qu_id']; echo "<br>"; echo $row['value']; echo "<p>"; }?>[/code]Basically, you echo the player id everytime there is a new one, you always echo the other information.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10066-displaying-recordshelp/#findComment-37453 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.