Jump to content

MySQL Query Sort Order and PHP 5.2.1


TRI0N

Recommended Posts

Can't seem to get this fixed.  Like there is no answer to this problem?

 

Sort is working at pulling out the scores but now it is duplicating the Player name.  Results looks like this:

 

1 Joe Dirt 54

2 Joe Dirt 73

 

When it should be:

 

1 Joe Dirt 54

2 John Doe 73

 

Here is the code..

 

 

<?php
$i = 0 ;

// Extract Score Data 1
$result9 = mysql_query("SELECT * FROM scores WHERE (eventid = '$eventid' AND round = '2' AND complete = '1') ORDER BY gross ASC") ;
while($row = mysql_fetch_row($result9)) {
$playerid = $row[0] ;
//$eventid = $row[1] ;
$gross3 = $row[22] ;
$net3 = $row[23] ;
$stable_gross3 = $row[24] ;
$stable_net3 = $row[25] ;

$result10 = mysql_query("SELECT * FROM players WHERE (eventid = '$eventid' AND playerid = '$playerid')") ;
while($row = mysql_fetch_row($result10)) {
$fname = $row[4] ;
$lname = $row[5] ;
$gkname = $row[6] ;
$score = $gross3 ;
$i = $i + 1 ;

echo "<tr>" ;
echo "<td width=\"10%\">" ;
echo "<p align=\"center\">$i</td>" ;
echo "<td width=\"80%\">" ;
echo "<p align=\"left\">".$fname." ".$lname."      <img src=\"images/gk.jpg\" alt=\"Member\"</td>" ;
echo "<td width=\"10%\">" ;
echo "<p align=\"center\">".$score."</td>" ;
echo "</tr>" ;
  }
}
?>

 

Please help me get this fixed before I jump in front of a UPS Truck...

Link to comment
Share on other sites

Okay this is what I got once I did a little comment out of a few things:

 

Array
(
    [0] => 1
    [playerid] => 1
    [1] => 1
    [eventid] => 1
    [2] => 2
    [courseid] => 2
    [3] => -2.5
    [phcp] => -2.5
    [4] => Joe
    [fname] => Joe
    [5] => Dirt
    [lname] => Dirt
    [6] => JD
    [gkname] => JD
    [7] => Male
    [gender] => Male
    [8] => 2
    [rounds_comp] => 2
)
Array
(
    [0] => 1
    [playerid] => 1
    [1] => 1
    [eventid] => 1
    [2] => 2
    [courseid] => 2
    [3] => -2.5
    [phcp] => -2.5
    [4] => Joe
    [fname] => Joe
    [5] => Dirt
    [lname] => Dirt
    [6] => JD
    [gkname] => JD
    [7] => Male
    [gender] => Male
    [8] => 2
    [rounds_comp] => 2
)

 

Link to comment
Share on other sites

So don't you see why the name is the same? You're just selecting the same player ID over and over.

 

So the problem lies here:

$result9 = mysql_query("SELECT * FROM scores WHERE (eventid = '$eventid' AND round = '2' AND complete = '1') ORDER BY gross ASC") ;
while($row = mysql_fetch_row($result9)) {

 

Where you get the $playerid.

Do the same thing with that row and figure out why you keep getting 1 instead of 1 and 2.

Link to comment
Share on other sites

Okay checked that one too but no offence here this is just rubbing my problem in my face.  I know the looping error is between result9 and result10.

 

How to fix this so that it works? I have no clue.. Thats what I'm hoping to get out of seeking help.

 

Why is it using the same $playerid over and over?  I have no clue!

 

Is there a way I should combine the two queries?  If so a newbie tip at doing so would be nice.

Link to comment
Share on other sites

What are the results of the query? I suspect it has something like player 1 and player 2 - you're only ever getting player 1, because you always get $row[0]. You need to get that other player's ID. Without seeing the actual results I can't help anymore than that

Link to comment
Share on other sites

Sorry had to take a quick break to pick up daughters perscription.

 

Okay yes the results was 2 differnt score data for Joe Dirt and John Doe..

 

Array
(
    [0] => 1
    [eventid] => 1
    [1] => 3
    [playerid] => 3
    [2] => 2
    [round] => 2
    [3] => 18
    [holes] => 18
    [4] => 3
    [hole1] => 3
    [5] => 3
    [hole2] => 3
    [6] => 3
    [hole3] => 3
    [7] => 3
    [hole4] => 3
    [8] => 3
    [hole5] => 3
    [9] => 3
    [hole6] => 3
    [10] => 3
    [hole7] => 3
    [11] => 3
    [hole8] => 3
    [12] => 3
    [hole9] => 3
    [13] => 3
    [hole10] => 3
    [14] => 3
    [hole11] => 3
    [15] => 3
    [hole12] => 3
    [16] => 3
    [hole13] => 3
    [17] => 3
    [hole14] => 3
    [18] => 3
    [hole15] => 3
    [19] => 3
    [hole16] => 3
    [20] => 3
    [hole17] => 3
    [21] => 3
    [hole18] => 3
    [22] => 54
    [gross] => 54
    [23] => 10
    [net] => 10
    [24] => 
    [stable_gross] => 
    [25] => 
    [stable_net] => 
    [26] => 1
    [complete] => 1
)
Array
(
    [0] => 1
    [eventid] => 1
    [1] => 1
    [playerid] => 1
    [2] => 2
    [round] => 2
    [3] => 18
    [holes] => 18
    [4] => 6
    [hole1] => 6
    [5] => 4
    [hole2] => 4
    [6] => 3
    [hole3] => 3
    [7] => 4
    [hole4] => 4
    [8] => 4
    [hole5] => 4
    [9] => 5
    [hole6] => 5
    [10] => 5
    [hole7] => 5
    [11] => 3
    [hole8] => 3
    [12] => 4
    [hole9] => 4
    [13] => 4
    [hole10] => 4
    [14] => 3
    [hole11] => 3
    [15] => 4
    [hole12] => 4
    [16] => 4
    [hole13] => 4
    [17] => 3
    [hole14] => 3
    [18] => 5
    [hole15] => 5
    [19] => 3
    [hole16] => 3
    [20] => 5
    [hole17] => 5
    [21] => 4
    [hole18] => 4
    [22] => 73
    [gross] => 73
    [23] => 76
    [net] => 76
    [24] => 
    [stable_gross] => 
    [25] => 
    [stable_net] => 
    [26] => 1
    [complete] => 1
)

 

So I'm thinking its got to do where my closing } is located.  It should be located after the second result (10) and before the echo statements?

 

Thanks for the help BTW.. This is driving me crazy.. Cross Table Queries is new to me where I want to list muli results rather then just a single result and its got me going bonkers.

Link to comment
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.