I am trying to loop through a table and get the length of it so I can ensure that on the final iteration of the loop, it does what I want. I tried used $r=mysql_fetch_array and count($r) but it gives me 14 when I only have for entries in the table.
Here’s my php. As I said there are 4 rows in the table that I am pulling this from, but it isn’t counting them properly. Is there something I am missing or do I need to create a loop first to count the rows in the table?
<?php
$count =0;
$loop = 0;
$q=mysql_query("select * from users");
while($row = mysql_fetch_array($q)){
if($count==0){
echo "<div class='lawyerRow'>";
echo"<span class='lawyerBubble'><img src='images/lawyer.png' /><h4>".$row["fname"]." ".$row["lname"]."</h4><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></span>";
$count++;
if(count($row) == $loop){
echo"</div>";
}
}elseif($count==3){
echo "</div>";
if(count($row) != $loop){
echo "<div class='lawyerRow'>";
echo"<span class='lawyerBubble'><img src='images/lawyer.png' /><h4>".$row["fname"]." ".$row["lname"]."</h4><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></span>";
$count=1;
}
}else{
echo"<span class='lawyerBubble'><img src='images/lawyer.png' /><h4>".$row["fname"]." ".$row["lname"]."</h4><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></span>";
$count++;
if(count($row) == $loop){
echo"</div>";
}
}
echo "loop = ".$loop;
echo "count = ". count($row);
$loop++;
}
?>
Thanks for the help in advanced.