Jump to content

Recommended Posts

Alright, Didn't get any good responds yesterday so I try again, my thread kinda died..

So the problem is now that I have to limit the data to a max of 25 per page, which is simple by itself, but also what I have to do is to keep it categorized, and I just can't seem to get through with it, can someone enlighten me please?

Here is some example code I've tried to fix, but it keeps messing up! The loops gets screwed up..



Here's what I want to get

Category 1
- Comment 1
- Comment 2
Category 2
- Comment 1
- Comment 2



Note: This is only testing/example code of what I'm meaning

Code:
[code]
<b>
<?
echo "<table border=1>";
if(!isset($_GET['page'])){
        $numPage = 1;
}
else{
        $numPage = $_GET['page'];
}
$rowsPerPage = 2;
$offset = ($numPage - 1) * $rowsPerPage;
$testy = mysql_fetch_array(mysql_query("SELECT category FROM myfriends limit $offset, 1"));
$test = mysql_query("SELECT * FROM myfriends limit $offset, $rowsPerPage");
$category=$testy[category];
while(($category < 5) && ($t = mysql_fetch_array($test))){
        if($category==1)
        $cat_text = "Friends";
        if($category==2)
        $cat_text = "Family";
        if($category==3)
        $cat_text = "School";
        if($category==4)
        $cat_text = "The Rest";
        echo "<tr><td>$cat_text</td></tr>";
        $test3 = mysql_query("SELECT * FROM myfriends where category='$category' limit $offset, $rowsPerPage") or die(mysql_error());

                while($e = mysql_fetch_array($test3)){

                echo "<tr><td>$e[comment]</td></tr>";


                }
$category = $category+1;
}
echo "</table>";
$topage = $numPage +1;
echo "<a href=test.php?page=$topage>></a>";
?>
</b>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/17189-paging-multicategory/
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.