tags:

views:

62

answers:

1

I use GET to get the id of a result.

$id = $_GET['id'];

I then use the following code:

        <?
    $q = $database->friendlyDetails($id);
    while( $row=mysql_fetch_assoc($q) )
    {
        $hu = $row['home_user'];
        $ht = $row['home_team'];
        $hs = $row['home_score'];
        $au = $row['away_user'];
        $at = $row['away_team'];
        $as = $row['away_score'];
        $game = $row['game'];
        $name = $row['name'];
        $match = $row['match_report1'];
        $compid = $row['compid'];
        $date = $row['date_submitted'];
        $sub = $row['user_submitted'];
    }
    ?>

And friendDetails-

   function friendlyDetails($i)
   {
   $q = "SELECT *
        FROM ".TBL_SUB_RESULTS." 
        INNER JOIN    ".TBL_FRIENDLY."
        ON ".TBL_FRIENDLY.".id = ".TBL_SUB_RESULTS.".compid
        WHERE ".TBL_SUB_RESULTS.".id = '$i'";
   return mysql_query($q, $this->connection);
   }

For some reason, the code will only return what is under id =1. Can anyone see anything obvious I am doing wrong?

EDIT SUB RESULTS TABLE

id | compid |home_user | home_team | away_user | away_team | home_score |away_score | report1 | date | submitted

FRIENDLY TABLE

id | name | game

A: 

Hey Luke,

Have you tried doing a LEFT JOIN instead of an INNER JOIN? Try this,

function friendlyDetails($i) {
    $q = "SELECT *
          FROM ".TBL_SUB_RESULTS." 
          LEFT JOIN ".TBL_SUB_RESULTS."
          ON ".TBL_SUB_RESULTS.".compid = ".TBL_FRIENDLY.".id
          WHERE ".TBL_SUB_RESULTS.".id = $i";
    return mysql_query($q, $this->connection);
}
Metropolis
Tried this, still didnt work.I cant get my head around this. It only ever wants to deal with id = 1. I have no idea????
Luke
In your database....i assume that there are multiple values for compid in the first table....and those are related to the id in the FRIENDLY TABLE? What value is coming in from the $_GET? and are there more then 1 of those values in the compid col?
Metropolis
Yeah, if id=1 from GET, the query will return the correct values.BUT, if i then go, id = 2, the values returned are still the same as id = 1. So it's almost returning id = 1 everytime. If there is no id = 1, nothing is returned. The values in compid can be 1,2,3,4,5 depending on whether its in the friendly table.
Luke
I have now fixed it, put the GET directly into the function rather than through a variable. And it works.Thats so strange....
Luke
Hmmmmmmmmmm....
Metropolis