开发者

SQL return error within PHP

开发者 https://www.devze.com 2022-12-31 17:35 出处:网络
I use GET to get the id of a result. $id = $_GET[\'id\']; I then use the following code: <? $q = $database->friendlyDetails($id);

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

开发者_JAVA技巧

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

精彩评论

暂无评论...
验证码 换一张
取 消