我没有收到错误,但它也没有返回行值。 我该如何解决这个问题?
<?php
//DATABASE
$dbConn = mysql_connect($host,$username,$password);
mysql_select_db($database,$dbConn);
$SQL = mysql_query("SELECT N.*, C.CatID FROM News N INNER JOIN Categories C ON N.CatID = C.CatID WHERE N.Active = 1 ORDER BY DateEntered DESC");
while ( $Result = mysql_fetch_array($SQL) or die(mysql_error())) {
$CatID[] = $Result[CatID];
$NewsName[] = $Result[NewsName];
$NewsShortDesc[] = $Result[NewsShortDesc];
}
// mysql_free_result($Result);
?>
<div class="toparticle">
<span class="section"><?=$CatID[0] ?> </span>
<span class="headline"><?=$NewsName[0] ?></span>
<p><?=$NewsShortDesc[0] ?></p>
</div>
答案 0 :(得分:1)
$Result[CatID];
需要
$Result['CatID'];
和
while ( $Result = mysql_fetch_array($SQL) or die(mysql_error())) {
需要
while ( $Result = mysql_fetch_array($SQL)) {
答案 1 :(得分:0)
让我们正确地做到这一点 如果由于临时存储以外的任何原因没有使用数组来循环显示,你可以直接将显示代码放入while循环。
<?php
//DATABASE
$dbConn = mysql_connect($host,$username,$password);
mysql_select_db($database,$dbConn);
$SQL = mysql_query("SELECT N.*, C.CatID FROM News N INNER JOIN Categories C ON N.CatID = C.CatID WHERE N.Active = 1 ORDER BY DateEntered DESC");
while ( $Result = mysql_fetch_array($SQL) ) {
?>
<div class="toparticle">
<span class="section"><?= $Result['CatID'] ?></span>
<span class="headline"><?= $Result['NewsName'] ?></span>
<p><?= $Result['NewsShortDesc'] ?></p>
</div>
<?php
}
//mysql_free_result($Result);
?>