I'm attempting to use a for statement to dynamically change <div> and <a> id and class names via based on the number of records returned from a query. I'm running into a problem and they are not iterating, both are remaining at 0. Thank you in advance!
For statement:
$limit = mysql_num_rows($result);
if (mysql_num_rows($result) >= '1')
{
for ($i = 0; $i <= $limit; $i++)
Here are the id and class I'm trying to dynamically change.
<a id='link$i'
<div class=\"div$i programDesc\">
both are remaining through every iteration:
<a id='link0'
<div class="div0 programDesc">
Code below:
Code: Select all
Query left out...
$result=mysql_query($query);
echo mysql_error();
$color="1";
//begin iterations
$limit = mysql_num_rows($result);
if (mysql_num_rows($result) >= '1')
{
for ($i = 0; $i <= $limit; $i++)
//start db query while loop
while ($row = mysql_fetch_assoc($result))
{
$title = $row['title'];
$node = $row['nid'];
$shortDesc = $row['field_short_desc_value'];
$college = $row['field_college_value'];
if($color==1){
echo"</tr>";
echo"<tr class='even' onMouseOver='this.style.backgroundColor='#e0ddda'' onMouseOut='this.style.backgroundColor='''>";
echo"<td><a id='link$i' href='#' title='Click for program details'>$title</a></td>";
echo"<td>$college</td>";
echo"</tr>";
echo"<tr><td>
<div class=\"div$i programDesc\">
<p>title: $title </p>
<p>short desc: $shortDesc</p>
</div>
</td></tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo"<tr class='odd' onMouseOver='this.style.backgroundColor='#e0ddda'' onMouseOut='this.style.backgroundColor='''>";
echo"<td><a id='link$i' class='basic' href='#' title='Click for program details'>$title</a></td>";
echo" <td>$college</td>";
echo"</tr>";
echo"<tr><td>
<div class=\"div$i programDesc\">
<p>title: $title </p>
<p>short desc: $shortDesc</p>
</div>
</td></tr>";
// Set $color back to 1
$color="1";
} //close else
} // close for
} // close while
?>
</tr>
</tbody>
</table>
</div>