Reputation: 35
i have a 2 part code. the first part of the code tells me the number of records in a table based on the situation, the second part of the code pulls and displays the actual record information. In the Below code, it displays the correct record count with is 3, but when it tries to pull the information to display it, it only shows 1 record.
$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>';
any help spotting out what's causing the records to not display properly is always much appreciated.
Upvotes: 0
Views: 272
Reputation: 6877
Change this part :
while($courselist=mysql_fetch_array($depcourselist) )
$coursename = $courselist['fullname'];
{
to this:
while($courselist=mysql_fetch_array($depcourselist) )
{
$coursename = $courselist['fullname'];
Notice the Curly Braces {
and use
mysql_fetch_assoc
instead of
mysql_fetch_array
(It's better to do so as it's more optimized you only need associative array here, no need for numerical array)
Upvotes: 2
Reputation: 1869
Use this code,
$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>';
I changed the loop,
while($courselist=mysql_fetch_array($depcourselist) )
{ // Changed here
$coursename = $courselist['fullname'];
.
.
.
Upvotes: 0