Jump to content

Loop the output of mysql result


art15

Recommended Posts

Hi,

 

When I fetch the result from mysql, it gives me the result of all the rows. what I want is to group the output of mysql into group of 4.

eg output of $new into a group of 4;

 

$sSQL="select something from table something between a and b;";

$result=mysql_query($sSQL) or die('Error, cannot retrieve the information');

while($rs=mysql_fetch_row($result)){

echo $new=$rs[0]."<br>";

}

 

Thanks

 

 

Link to comment
Share on other sites

You want just 4 items shown?  If so can you add a "LIMIT 4" to the end of your query?  Or is there more to the problem than that?  Explain in a little more detail and I'll whip an solution for you. 

 

Oh and please use the "code" tags in the future.

Link to comment
Share on other sites

Thanks for your reply.

 

I just don't want to LIMIT it to 4. When the output result has 40 rows. I want to split it into chunks of 4. so instead of one variable say $total displaying all the 40 rows. I want $total1 to be first group having 4 values, $total2 having next 4 and so on.. I belive it should be an array.

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.