0

Please I get this error code when executting this script Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a777gqka/public_html/testserver/index.php on line 47

$query = mysql_query("SELECT
e.id,
ts.name AS stage_name,
DATE_FORMAT(e.startdate, '2013-05-15') AS startdate,
DATE_FORMAT(e.startdate, 'H:i') AS starttime,
MIN(if( ep.number = 1, p.name, NULL)) AS home_team,
if(e.status_type = \"notstarted\", \"-\",(MIN(if(ep.number = 1, r.value, NULL))))  AS home_score,
if(e.status_type = \"notstarted\", \"-\",(MIN(if(ep.number = 2, r.value, NULL)))) AS away_score,
MIN(if(ep.number = 2, p.name, NULL)) AS away_team,
es.name AS status_text
FROM
tournament_template AS tt INNER JOIN
tournament AS t ON t.tournament_templateFK = tt.id INNER JOIN
tournament_stage AS ts ON t.id = ts.tournamentFK INNER JOIN
event AS e ON ts.id = e.tournament_stageFK INNER JOIN
event_participants AS ep ON e.id = ep.eventFK LEFT JOIN
status_desc AS es ON e.status_descFK = es.id LEFT JOIN
participant AS p ON ep.participantFK = p.id LEFT JOIN
result AS r ON ep.id = r.event_participantsFK AND r.result_code = \"runningscore\" LEFT JOIN
property AS prop ON e.id = prop.objectFK AND prop.object =\"event\" AND prop.name = \"Live\"
WHERE
tt.sportFK = ".$sportFK."  AND
e.startdate BETWEEN ".$TODAY_FROM." AND ".$TODAY_TO." AND
prop.value = \"yes\"
GROUP BY
e.id
ORDER BY 
ts.id, e.startdate, e.id");
while($row = mysql_fetch_assoc($query)){
// Do something
}
4

4 に答える 4

0
 $query = "SELECT .... ";
 if($result = mysql_query($query)){
     while($row = mysql_fetch_assoc($result)){
          //...
     }
 } else {
     echo mysql_error();
 }

エラーを出力する必要があることに加えて、少なくとも mysqli を使用する必要があります。mysql_* 関数は非推奨であり、PHP 5.5 で削除されます。

于 2013-04-19T12:03:30.020 に答える
0

クエリを実行していません。

while ループの前に追加$result = mysql_query($query)し、ループ テストを次のように変更します。$row = mysql_fetch_assoc($result)

また、mysql_* 関数は推奨されておらず、PHP の将来の更新で削除される予定です。mysqli_* または PDO に切り替えます。

個人的にはPDOをお勧めします。

于 2013-04-19T12:04:39.043 に答える
0
$query = mysql_query("SELECT...") or die(mysql_error());
if ($query){
while($row = mysql_fetch_assoc($query)){
// Do something
}
}
于 2013-04-19T12:57:58.643 に答える
-1

これを試してください

if(mysql_num_rows($query) > 0){

   while($row = mysql_fetch_assoc($query)){
   // Do something
   }
}
else{
    echo "No record found";
}
于 2013-04-19T12:02:10.893 に答える