Jump to content

how to break while loop some specific records


realcoder

Recommended Posts

i am fetching some data from my database

want to know that how can i show  4 or 5 or etc records in one td then automatic start next tr

this is code

my code fetching all record in td i want to separte record after few record

someone explain

 

my code is like

 

$que = "SELECT * FROM movies where catid='$id'";

 

$exe = mysql_query($que);

while ($get = mysql_fetch_array($exe)){

 

                echo"<td height='400' align='left' valign='top'><a href='songs.php?movie=".$get['name']."'>".$get['name']."<br/><img width='100' height='130' src='".$get['picture']."' /></a>

                </td>";

 

 

 

please help buddies

$que = "SELECT * FROM movies where catid='$id'";

 

$exe = mysql_query($que);

while ($get = mysql_fetch_array($exe)){

 

                echo"<td height='400' align='left' valign='top'><a href='songs.php?movie=".$get['name']."'>".$get['name']."<br/><img width='100' height='130' src='".$get['picture']."' /></a>

                </td>";

 

If I understand the problem, I have something pretty similar in my code, I went with a simple counter solution as follows:

$Column = 1;
while ($get = mysql_fetch_array($exe)){
if ($Column==1)  { echo "<tr>";}
echo"<td height='400' align='left' valign='top'>
<a href='songs.php?movie=".$get['name']."'>".$get['name']."<br/>
<img width='100' height='130' src='".$get['picture']."' /></a>
</td>";
if ($Column==5) { echo "</tr>";
$Column += 1;
if ($Column==6) { $Column = 1;}
}

 

That will take a new row every 5 records :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.