Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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