Jump to content

Displaying Records...HELP!


schone

Recommended Posts

Hi all!

I have the following table:

[b]recovery_interventions[/b]
- id
- player_id
- date
- qu_id
- value

Here 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 : 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

[b]At the moment its displaying:[/b]

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!
Link to comment
https://forums.phpfreaks.com/topic/10066-displaying-recordshelp/
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/10066-displaying-recordshelp/#findComment-37453
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.