[英]rows not displaying in mysql query
我有2部分代碼。 代碼的第一部分告訴我基於情況的表中的記錄數,代碼的第二部分提取並顯示實際的記錄信息。 在下面的代碼中,它顯示正確的記錄計數為3,但是當它嘗試提取信息以顯示它時,它只顯示1條記錄。
$depcourselist=mysql_query("select * from organization_dep_courses odc left join course c on odc.courseid=c.id where orgid=$orgid and depid=$departmentid");
echo '<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#eaeaea" height="40">
<th align="left">Course Catalog<span>('.$countdepcourses.')</span></th>
</tr>';
while($courselist=mysql_fetch_array($depcourselist) )
$coursename = $courselist['fullname'];
{
if($coursecolor==1)
{
echo "<tr bgcolor='#f1f1f1' width='100%' height='25'>
<td align='left'>".$coursename."<a href='#'><img src='".$remove."' /></a></td>
</tr>";
$coursecolor="2";
}
else
{
echo '<tr bgcolor="#ffffff" height="25">
<td align="left">'.$coursename.'<a href="#"><img src="'.$remove.'" /></a></td>
</tr>';
$coursecolor="1";
}
}
echo '</table>';
任何幫助發現導致記錄無法正常顯示的內容總是非常感激。
改變這一部分:
while($courselist=mysql_fetch_array($depcourselist) )
$coursename = $courselist['fullname'];
{
對此:
while($courselist=mysql_fetch_array($depcourselist) )
{
$coursename = $courselist['fullname'];
注意卷曲大括號{
並使用
mysql_fetch_assoc
代替
mysql_fetch_array
(最好這樣做,因為它更優化你只需要關聯數組,不需要數值數組)
使用此代碼,
$depcourselist=mysql_query("select * from organization_dep_courses odc left join course c on odc.courseid=c.id where orgid=$orgid and depid=$departmentid");
echo '<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#eaeaea" height="40">
<th align="left">Course Catalog<span>('.$countdepcourses.')</span></th>
</tr>';
while($courselist=mysql_fetch_array($depcourselist) )
{ // Changed here
$coursename = $courselist['fullname'];
if($coursecolor==1)
{
echo "<tr bgcolor='#f1f1f1' width='100%' height='25'>
<td align='left'>".$coursename."<a href='#'><img src='".$remove."' /></a></td>
</tr>";
$coursecolor="2";
}
else
{
echo '<tr bgcolor="#ffffff" height="25">
<td align="left">'.$coursename.'<a href="#"><img src="'.$remove.'" /></a></td>
</tr>';
$coursecolor="1";
}
}
echo '</table>';
我改變了循環,
while($courselist=mysql_fetch_array($depcourselist) )
{ // Changed here
$coursename = $courselist['fullname'];
.
.
.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.