2

我有这个代码:

<?php
include 'connect.inc.php';  
include 'header.inc.php';


$mesiace  = array("Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl",     
"August", "September", "Október", "November", "December");

echo '<div id="rozpis">';
$sql = "SELECT game_id, rival_id, result, h_a, UNIX_TIMESTAMP(datum) AS datum FROM        game ORDER BY datum ASC";
$result = mysql_query($sql, $db) or die("ERROR: ".mysql_error());
if(mysql_num_rows($result) > 0)
{
echo '<table>';
echo   '<tr><td>Dátum</td><td>Domáci</td><td>Hostia</td><td>Výsledok</td></tr>';
while($row = mysql_fetch_array($result)) //here is the problem
{
extract($row);
$prikaz = 'SELECT rival_id, name FROM rival WHERE rival_id = '. $rival_id;
$vystup = mysql_query($prikaz, $db) or die(mysql_error($db));
$rival = mysql_fetch_array($vystup);
echo '<tr>';
echo '<td>' .date("j. F Y", $datum). '</td>';
if ($h_a == 1)
{
echo '<td> Capitals </td>';
echo '<td>' .$rival['name']. '</td>';
}
else 
{
echo '<td>' .$rival['name']. '</td>';
echo '<td> Capitals </td>';
}
echo '<td><a href="zapas.php?zapas='. $game_id.'">' .$result. '</td>';
echo '</tr>';  
}
echo '</table>';
}
else
echo 'No matches';

echo '</div>';

include 'zahlavie.php';
?> 

当我运行这个脚本时,它会写下这个警告:

Warning: mysql_fetch_array() expects parameter 1 to be resource,
string given in H:\xampp\htdocs\rozpis.php on line 16

真不知道哪里出了问题。在表中我有三行,但它只写第一行,然后是这条消息。当我$query在 phpMyAdmin 中运行时,它运行正确,或者当我使用echo mysql_num_rows($result)它时,它也正确返回。

4

1 回答 1

5

问题是您正在使用该函数extract,并且您的数据库列之一被命名为“结果”。因此将用一些字符串覆盖变量 $result,这当然是错误的。

$sql = "SELECT game_id, rival_id, result, h_a, UNIX_TIMESTAMP(datum) AS datum FROM        game ORDER BY datum ASC";
$result = mysql_query($sql, $db) or die("ERROR: ".mysql_error());
while($row = mysql_fetch_array($result)) {
    extract($row); // <- here is the problem
于 2012-04-27T14:18:23.470 回答