不在mysql查询中显示的行

时间:2013-03-26 04:57:51

标签: php mysql

我有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>';

任何有助于发现导致记录无法正常显示的内容的帮助总是非常受欢迎。

2 个答案:

答案 0 :(得分:2)

更改此部分:

while($courselist=mysql_fetch_array($depcourselist) )
$coursename = $courselist['fullname'];
{

到此:

while($courselist=mysql_fetch_array($depcourselist) )
{
$coursename = $courselist['fullname'];

请注意大括号{

并使用

mysql_fetch_assoc 

而不是

mysql_fetch_array 

(最好这样做,因为它更优化你只需要关联数组,不需要数值数组)

答案 1 :(得分:0)

使用此代码,

  $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'];
.
.
.
相关问题