Jump to content

still have a pagination problem!


Noskiw

Recommended Posts

<?php

$id = $_GET['id'];

$page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page'];
$page = ceil($page);
$limit = 10;

$start = $limit;
$end = $page*$limit-($limit);

if(isset($id)){
$sql = "SELECT * FROM forum_topics WHERE id='".$id."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo "This topic does not exist!\n";
}else{
$row = mysql_fetch_assoc($res);
$sql2 = "SELECT admin FROM forum_sub_cats WHERE id='".$row['cid']."'";
$res2 = mysql_query($sql2) or die(mysql_error());
$row2 = mysql_fetch_assoc($res2);
if($row2['admin'] == 1 && $admin_user_level == 0){
echo "You cannot view this topic because you are not an admin!\n";
}else{
$a = (isa($row['uid'])) ? "<font style=\"color:#800000;\">ADMIN</font>" : "";
echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n";
echo "<tr><td colspan=\"2\" align=\"left\"  class=\"forum_header\"><b><font size=\"3\">".$row['title']."</font></b><font size=\"3\"> - Posted On: <em>".$row['date']."</em></font></td></tr>\n";
echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\"  class=\"forum_header\">".uid($row['uid'], true)."<br>Posts: 0<br>".$a."</td>";
echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">";
echo topic($row['message']);
echo "</td>\n";
echo "</tr>\n";

$amount_check = "SELECT * FROM forum_replies WHERE tid='".$tid."'";
$amount_check_res = mysql_query($amount_check) or die(mysql_error());
$amount_count = mysql_num_rows($amount_check_res);
$pages = ceil($amount_count/$limit);

$previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>";
$nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; 
echo "<tr><td align=\"right\" colspan=\"2\">\n";
echo "Pages: ";

echo $previous;
for($i=1;$i<=$pages;$i++){
    $href = ($page == $i) ? " ".$i." " : " <a href=\"./index.php?act=create&id=".$i."\">".$i."</a> ";
    
    echo $href;
}
echo $nextpage;
echo "</td></tr>\n";
$select_sql = "SELECT * FROM `forum_replies` ORDER BY id ASC LIMIT ".$end.",".$start."";
$select_res = mysql_query($select_sql) or die(mysql_error()); 

while($rowr = mysql_fetch_assoc($select_res)){
echo "<tr><td colspan=\"2\" align=\"left\"  class=\"forum_header\"><font size=\"3\"> - Posted On: <em>".$rowr['date']."</em></font></td></tr>\n";
echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\"  class=\"forum_header\">".uid($rowr['uid'], true)."<br>Posts: 0<br>".$a."</td>";
echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">";
echo topic($rowr['message']);
echo "</td>\n";
echo "</tr>\n";
}

echo "<form method=\"post\" action=\"./forum-index.php?act=reply&id=".$row['id']."\">\n";
echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%\" name=\"reply\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"add reply!\" style=\"width:90%\" /></td></tr>\n";

echo "</table>\n";
}
}
}else{
echo "Please view a valid topic!\n";
}

?>

 

the problem is that the replies show up in both topics, theyre not meant to.

 

and the page number and links to the next page wont show up.

Link to comment
Share on other sites

  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

$select_sql = "SELECT * FROM `forum_replies` ORDER BY id ASC LIMIT ".$end.",".$start."";

You need a WHERE clause that specifies to just get the replies for the topic in question. Missed that step but otherwise looks pretty good.

Do that and then we'll see what can be done about the "previous" and "next" links not showing up...

Link to comment
Share on other sites

$select_sql = "SELECT * FROM `forum_replies` ORDER BY id ASC LIMIT ".$end.",".$start."";

You need a WHERE clause that specifies to just get the replies for the topic in question. Missed that step but otherwise looks pretty good.

Do that and then we'll see what can be done about the "previous" and "next" links not showing up...

 

but i don't know where to add the where statement

 

maybe it could be

 

$select_sql = "SELECT * FROM `forum_replies` ORDER BY id ASC LIMIT WHERE id= ".$end.",".$start."";

Link to comment
Share on other sites

$select_sql = "SELECT * FROM `forum_replies`WHERE id= ".$id." ORDER BY id ASC LIMIT  ".$end.",".$start."";

I just noticed, end and start seem to be reversed. lol

example of getting the first through 30th entry

$select_sql = "SELECT * FROM `forum_replies`WHERE id= ".$id." ORDER BY id ASC LIMIT 0,29"

the next 30

$select_sql = "SELECT * FROM `forum_replies`WHERE id= ".$id." ORDER BY id ASC LIMIT 30,59"

Link to comment
Share on other sites

what you are doing with pagination is getting reply x through z, right?

on page one, how many replies do you want to show?

if you wanted to show 30 replies, you'd use a query of

$select_sql = "SELECT * FROM `forum_replies`WHERE id= ".$id." ORDER BY id ASC LIMIT 0,29"

0 is the first returned result from mysql (1 is the second returned)...

I'm guessing you didn't write this stuff yourself then, you've just been modifying it.

Link to comment
Share on other sites

wait a second, what is the table structure for your forum_replies table? What are the fields?

$select_sql = "SELECT * FROM `forum_replies`WHERE XXX= ".$id." LIMIT ".$Start.", ".$End." ORDER BY id ASC "

XXX column is the column that relates the reply to the original post.

with

$select_sql = "SELECT * FROM `forum_replies`WHERE id= ".$id." ORDER BY id ASC LIMIT 0,29"

u are only pulling the reply that happens to have the same id as the id of the original post hence why you only get one.

Link to comment
Share on other sites

I'm guessing tid is "Topic id" creating the relation between the topic and the reply. correct?

so, query for all replies for topic selected would be

$select_sql = "SELECT * FROM `forum_replies`WHERE tid = ".$id." LIMIT ".$Start.", ".$End." ORDER BY id ASC "

Link to comment
Share on other sites

umm, hmm, lets add something for debugging purpose.

$select_res = mysql_query($select_sql) or die(mysql_error()); 

to

$select_res = mysql_query($select_sql) or die(mysql_error()."<br>".$select.res); 

that way if gives us the error message plus the query that was made so we can see what may have gone wrong. post what you get please.

Link to comment
Share on other sites

umm, hmm, lets add something for debugging purpose.

$select_res = mysql_query($select_sql) or die(mysql_error()); 

to

$select_res = mysql_query($select_sql) or die(mysql_error()."<br>".$select.res); 

that way if gives us the error message plus the query that was made so we can see what may have gone wrong. post what you get please.

 

this again

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ORDER BY id ASC' at line 1
res 

Link to comment
Share on other sites

sorry, 4 hours of sleep is catching up with me dude.

$select_res = mysql_query($select_sql) or die(mysql_error()."<br>".$select.res); 

to

$select_res = mysql_query($select_sql) or die(mysql_error()."<br>".$select_sql); 

 

again, sorry about that. try it again...

Link to comment
Share on other sites

ummm, crap. we need a mysql guru for quick answer! meanwhile, test a fail to test and success.

move the LIMIT to the end like so:

$select_sql = "SELECT * FROM `forum_replies`WHERE tid = ".$id." ORDER BY id ASC LIMIT ".$Start.", ".$End

this is just shooting in the dark, that's all. I'm not an expert, barely would consider myself above novice.

Link to comment
Share on other sites

ummm, crap. we need a mysql guru for quick answer! meanwhile, test a fail to test and success.

move the LIMIT to the end like so:

$select_sql = "SELECT * FROM `forum_replies`WHERE tid = ".$id." ORDER BY id ASC LIMIT ".$Start.", ".$End

this is just shooting in the dark, that's all. I'm not an expert, barely would consider myself above novice.

 

ok now it's working

 

this is it now

 

$select_sql = "SELECT * FROM `forum_replies`WHERE tid = ".$id." ORDER BY id ASC LIMIT ".$end.", ".$start."";

 

but now onto the pagination problem, i can't seem to get the number to show up, + the fact the the next link wont show up.

Link to comment
Share on other sites

The problem I think is with this

$nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; 

could it be

$nextpage = ($page+1 >= $pages) ? " Next »" : " <a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; 

I think that your fist page is 0, $pages has become 2

(13/10) = 1.3

round up is 2

$page = 1 initially, so

(1+1 >= 2) instead of (1+1 > 2)

Link to comment
Share on other sites

The problem I think is with this

$nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; 

could it be

$nextpage = ($page+1 >= $pages) ? " Next »" : " <a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; 

I think that your fist page is 0, $pages has become 2

(13/10) = 1.3

round up is 2

$page = 1 initially, so

(1+1 >= 2) instead of (1+1 > 2)

 

i have tried the one that you gave me, all it did was seperate the next and prev, the page number doesn't show up and the link still isn't there. i think i need to get rid of the question mark.

Link to comment
Share on other sites

(see the messages I posted on your forum  lol)

I added spaces to be sure they came up not as all one word.

the ? is there as part of the logic.

if $page+1 >= $pages then if it is show " Next »" else show the link.

!!!!F*CK, i'm tired.

less than! you want next as a link to the next one if there is a next page. god damn it!

$nextpage = ($page+1 <= $pages) ? " Next »" : " <a href=\"./index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>";

umm, but don't count on that working... lol    SOME ONE ELSE HELP PLEASE TOO

 

lets get this working than work on the numbers issue.

for debugging purposes, echo $page and $pages somewhere and make sure they are what you expect them to be.

echo "<br>page = ".$page;
echo "<br>pages = ".$pages;

Link to comment
Share on other sites

the pages keep on going, how do i make html entities work? like the ampersand (&) and the < and >. cause i don't know how to yet. also, i saw the posts you put, i will work on it.

 

and what i mean by the pages keep on going, when it goes to &page=2, it carries on forever, i went all the way to 100 and it was still there.

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.