简体   繁体   中英

SQL return error within PHP

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

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM