php - How to display the <div> as per data count displayed below? -
i have display below snippet according data available in db
<div id="testimonial-row"> <div id="testimonial"> <ul> <li>"hello world"</li> </ul> </div> <div id="testimonial"> <ul> <li>"hello world"</li> </ul> </div> <div id="testimonial"> <ul> <li>"hello world"</li> </ul> </div> </div>
that is, <div id="testimonial-row">
should created everytime count of data (here, hello world) becomes greater 3, hence in way if data count "16" the <div id="testimonial-row">
should created 6 times data displayed in created 6 <div>
tags
so 1 tell me how implement loop make happen in php?
echo '<div class="testimonial-row">'; ($i=1;$i<=$mysql_num_rows($res);$i++) { $row = mysql_fetch_array($res); echo '<div class="testimonial">'; echo ' <ul>'; echo ' <li>'.$row['field'].'</li>'; echo ' </ul>'; echo '</div>'; if ($i%3 == 0) echo '</div><div class="testimonial-row">'; } echo '</div>';
you should not use id="testimonial-row" or id="testimonial". instead use class="testimonial-row".
Comments
Post a Comment