PHP içinde hata döndüren bir SQL

1 Cevap php

Ben bir sonucu kimliği almak için GET kullanın.

$id = $_GET['id'];

Daha sonra aşağıdaki kodu kullanabilirsiniz:

        <?
    $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'];
    }
    ?>

Ve 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 | tarih | teslim

DOSTU TABLO

id | isim | oyun

1 Cevap

JOIN yerine bir INNER JOIN bir LEFT yapıyor denediniz mi? Bu deneyin,

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