这是我的网页代码:
<?php
$dbhost="****";
$dbname = '****';
$dbusername="********";
$dbpass="*****;
$con = mysql_connect("$dbhost","$dbusername","$dbpass");
mysql_select_db($dbname,$con);
?>
<main>
<table width='100%' align='center'>
<tr align='center'>
<?php
$sql = "SELECT * FROM file ORDER BY data";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$j = $num - 1;
$fyear = mysql_result($result, $j, "data");
$year = 2005;
while ($year <= $fyear)
{
$sql = "SELECT * FROM file WHERE posizione = 'uila/blindi.php' AND YEAR(data) = ".$year." ORDER BY data";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$num = mysql_num_rows($result);
$i = 0;
echo "<td>";
while ($i < $num)
{
$file = mysql_result($result, $i, "pdf");
$name = mysql_result($result, $i, "nome");
$type = mysql_result($result, $i, "type");
$path = mysql_result($result, $i, "posizione");
echo "<a href=\"opendoc.php?type={$type}&id={$i}&path={$path}\" TARGET=\"_self\">"?><?php echo $name; ?></a><br>
<?php
$i++;
}
echo "</td>";
$year++;
}
?>
</tr>
</table>
这是页面错误:
警告:
mysql_result()
[function.mysql-result]:无法在第47行的D:\ Inetpub \ webs \ uilanotiziecom \ bindi.php中跳转到MySQL结果索引2的第-1行
第47行是:$j = $num - 1;
我该如何解决?
答案 0 :(得分:0)
if ( $num >= 1 ) {
$j = $num - 1;
}
如果您的查询返回0行,则会收到错误,在这种情况下您所做的就由您决定
答案 1 :(得分:0)
我认为下面的sql查询返回的是你遇到问题的空结果。
$sql = "SELECT * FROM file ORDER BY data";
这就是$ j值为-1
的原因和FYI,
请使用正确的命名约定和唯一变量名称,因为您对这两个查询使用了 $ sql