0

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.

1
  • 1. Format the code. 2. Please show the code that correctly displays the count. Commented Mar 26, 2013 at 5:08

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

0

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'];
.
.
.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.