Jump to content


Photo

Displaying Records...HELP!


  • Please log in to reply
1 reply to this topic

#1 schone

schone
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 May 2006 - 03:10 PM

Hi all!

I have the following table:

recovery_interventions
- id
- player_id
- date
- qu_id
- value

Here is my 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>";
            
            }
        }
?>

Now MY PROBLEM :)

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 : 4
date : 10/10/06
qu_id : 4
value : 2

date : 10/10/06
qu_id : 6
value : 3

date : 10/10/06
qu_id : 9
value : 1

At the moment its displaying:

player_id : 4
date : 10/10/06
qu_id : 4
value : 2

date : 10/10/06
qu_id : 4
value : 2

player_id : 4
date : 10/10/06
qu_id : 6
value : 3

date : 10/10/06
qu_id : 6
value : 3

player_id : 4
date : 10/10/06
qu_id : 9
value : 1

date : 10/10/06
qu_id : 9
value : 1

I have wrecked my brain and the mysql.net and php.net manuals but get no where! Please help!

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 May 2006 - 04:31 PM

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:
<?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>";
            
        }
?>
Basically, you echo the player id everytime there is a new one, you always echo the other information.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users