...

View Full Version : Page Numbering Help!



birdbrain24
07-11-2007, 07:50 PM
Can Someone Add Page Numbering To This Script Please


<link rel=stylesheet href=../style.css type=text/css>
<?php
include"mysql_connect.php";
include"functions.php";

$username=$_SESSION['username'];

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));
$userlevel=$fetch->userlevel;

$topics=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$username'"));

$date=gmdate('F jS Y');
$time=gmdate('g:i:s a');
$datetime="$date at $time";

?>
<form id="form" name="form" method="post" action="newtopic.php">
<input type="submit" name="Submit" value="New Topic!" />
</form>
<table width=400 border=1 cellpadding=2 cellspacing=0 bordercolor=black class=table align=center>
<tr>
<td width=100% align=center class=header colspan=2>Forum</td>
</tr>

<?php
$query = mysql_query("SELECT * FROM `topics` WHERE `type`='important' ORDER BY `lastpost` DESC");
while($topics=mysql_fetch_object($query)){

if($topics->type == "important"){

if($userlevel == "Admin"){
echo "<tr><td class=text><u><b>Important:</b></u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Head"){
echo "<tr><td class=text><u><b>Important:</b></u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Mod"){
echo "<tr><td class=text><u><b>Important:</b></u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Users"){
echo "<tr><td class=text><u><b>Important:</b></u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td></tr>";
}
}
}

$query = mysql_query("SELECT * FROM `topics` WHERE `type`='sticky' ORDER BY `lastpost` DESC");
while($topics=mysql_fetch_object($query)){

if($topics->type == "sticky"){

if($userlevel == "Admin"){
echo "<tr><td class=text><u>Sticky:</u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Head"){
echo "<tr><td class=text><u>Sticky:</u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Mod"){
echo "<tr><td class=text><u>Sticky:</u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Users"){
echo "<tr><td class=text><u>Sticky:</u> ";
echo "<a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td></tr>";
}
}
}

$query = mysql_query("SELECT * FROM `topics` WHERE `type`='normal' ORDER BY `lastpost` DESC");
while($topics=mysql_fetch_object($query)){

if($topics->type == "normal"){

if($userlevel == "Admin"){
echo "<tr><td class=text><a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Head"){
echo "<tr><td class=text><a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Mod"){
echo "<tr><td class=text><a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td>
<td>
<a href='topics.php?delete=$topics->id'><img src='images/delete.gif' border='0' /></a>
</td>
</tr>";
}

if($userlevel == "Users"){
echo "<tr><td class=text><a href='posts.php?topic=$topics->id' target='frameright'>$topics->topic</a>";
if ($topics->locked == "Yes" ){ echo" (Locked)"; }
echo"</td></tr>";
}
}
}

$delete=$_GET[delete];
if($delete) {

if($userlevel == "Admin"){
echo "<META HTTP-EQUIV=\"Refresh\" target=\"_top\" CONTENT=\"0; URL=forum.php\">";
echo"Deleted!";
mysql_query("DELETE FROM topics WHERE id='$delete'");
mysql_query("DELETE FROM posts WHERE topicid='$delete'");
mysql_query("INSERT INTO `staff_logs` (`username`, `action`, `date`) VALUES ('$username', 'Delete Forum Topic = $delete', '$datetime');") or die (mysql_error());

}

if($userlevel == "Head"){
mysql_query("INSERT INTO `staff_logs` (`username`, `action`, `date`) VALUES ('$username', 'Delete Forum Topic = $delete', '$datetime') LIMIT 1;") or die (mysql_error());
mysql_query("DELETE FROM topics WHERE id='$delete'");
mysql_query("DELETE FROM posts WHERE topicid='$delete'");
echo "<META HTTP-EQUIV=\"Refresh\" target=\"_top\" CONTENT=\"0; URL=forum.php\">";
echo"Deleted!";
}

if($userlevel == "Mod"){
mysql_query("INSERT INTO `staff_logs` (`username`, `action`, `date`) VALUES ('$username', 'Delete Forum Topic = $delete', '$datetime');") or die (mysql_error());
mysql_query("DELETE FROM topics WHERE id='$delete'");
mysql_query("DELETE FROM posts WHERE topicid='$delete'");
echo "<META HTTP-EQUIV=\"Refresh\" target=\"_top\" CONTENT=\"0; URL=forum.php\">";
echo"Deleted!";
}

if($userlevel == "User"){
echo"Nice Try!<br>You Actions Have Been Logged!";
mysql_query("INSERT INTO `user_logs` (`username`, `action`, `date`) VALUES ('$username', 'Delete Forum Topic = $delete', '$datetime');")
or die (mysql_error());
}

}

?>

</table>

Thanks,
birdbrain24

stevenmw
07-11-2007, 09:16 PM
This tutorials is very good at explaining page numbering. Try taking a look.

http://www.phpfreaks.com/tutorials/73/0.php

birdbrain24
07-12-2007, 03:59 AM
I did it and i gets the page numbering but it goes over the limit on the first page and shows everything and on the second page it's the exact same stuff as the first page!

Boshi
07-12-2007, 04:05 AM
Well, I have no idea where you want the pages to go BUT here is an example:



$Number_Threads = mysql_num_rows(mysql_query("SELECT * FROM topics WHERE id = '$username'"));
$Threads_Per_Page = 20;
$Num_Pages = floor($Number_Threads / $Threads_Per_Page);
for( $i = 0; $i <= $Num_Pages; $i++){
echo "<a href=\"forum.php?id=$Forum_ID_Here&page=$i\">";
}


Thats a really basic example, you will need to edit the echo part to make the link suit your needs, just base from that.

birdbrain24
07-12-2007, 05:05 PM
Thanks I Hope This Will Work!

birdbrain24
07-12-2007, 05:20 PM
Same Problem With This One As The Last One! Could Someone Please Add It For Me!

Fumigator
07-12-2007, 06:44 PM
Don't demand that someone code your script for you. This is a learning forum, not a get-free-work forum. If the previous pagination script didn't work for you, have a look at Firepage's script, which is excellent and easy to implement. Find it at www.firepages.com.au

birdbrain24
07-12-2007, 06:55 PM
I Am Not Trying To Demand Someone To Do It For Me I Am Asking And I Am Not Trying To Get Free Work Done I Coded ALl What Is Done Myself! Just So You Know! And It Will Try That Link You Gave Me!

birdbrain24
07-12-2007, 07:42 PM
Still No Luck With That Link! I Don't Get This! I Tried About 15 Tutorails Showing You How To Do It With ! Query But My Script Haas 3 Queries Thats Why I Can't Do It! If Anyone Can Help Can You Please Do So!

All Thankz,
Birdbrain24

StupidRalph
07-12-2007, 07:55 PM
Here is the class: firepages pagination class (http://www.codingforums.com/showthread.php?t=74614) Firepages class intentionally steered clear of having his class deal with SQL statements that way it would be more extendable and should work in your case.

birdbrain24
07-12-2007, 07:58 PM
I Will Try The Link!

Boshi
07-12-2007, 08:41 PM
Are you sure it's my code wrong and not one of your SQL Queries?

I suggest adding: or print mysql_error()
at the end of every Query and before the semi-colon ( ; ).

And post whatever error you get, if you don't get any you might as well tell us whats the problem you said my code did.

Oh and, the code I give you requires you to edit the query that fetches the topics and add a LIMIT clause so you limit the amount of topics.

birdbrain24
07-13-2007, 03:13 AM
Are you sure it's my code wrong and not one of your SQL Queries?

I suggest adding: or print mysql_error()
at the end of every Query and before the semi-colon ( ; ).

And post whatever error you get, if you don't get any you might as well tell us whats the problem you said my code did.

Oh and, the code I give you requires you to edit the query that fetches the topics and add a LIMIT clause so you limit the amount of topics.

I Know Your Code Will Work For 1 Querie But That Code Wouldn't Work For 3 Queries! I Don't Think So Anyways! If It Do Work I Am Seriously Doing Something Wrong! Can Someone Please Help!

birdbrain24
07-13-2007, 03:17 AM
Are you sure it's my code wrong and not one of your SQL Queries?

I suggest adding: or print mysql_error()
at the end of every Query and before the semi-colon ( ; ).

And post whatever error you get, if you don't get any you might as well tell us whats the problem you said my code did.

Oh and, the code I give you requires you to edit the query that fetches the topics and add a LIMIT clause so you limit the amount of topics.

Thats My Problem! Because There Are 3 Queries And This Scripts Shows The Topics For A Forum That I Am Making For My Site It Has 3 Levels Of Topics! Important, Sticky and Normal! And They All Have Their Own Queries! So How Can I Put A Limit On Them!

Fumigator
07-13-2007, 06:00 AM
Why don't you use one query to retrieve all three types of threads? You could simply use a union to force them sorted the way you want...



SELECT blah, 1 as sort_order
FROM blah
WHERE type = 'IMPORTANT'
UNION ALL
SELECT blah, 2 as sort_order
FROM blah
WHERE type = 'STICKY'
UNION ALL
SELECT blah, 3 as sort_order
FROM blah
WHERE type = 'NORMAL'
ORDER BY sort_order, lastpost DESC

birdbrain24
07-13-2007, 03:20 PM
Why don't you use one query to retrieve all three types of threads? You could simply use a union to force them sorted the way you want...



SELECT blah, 1 as sort_order
FROM blah
WHERE type = 'IMPORTANT'
UNION ALL
SELECT blah, 2 as sort_order
FROM blah
WHERE type = 'STICKY'
UNION ALL
SELECT blah, 3 as sort_order
FROM blah
WHERE type = 'NORMAL'
ORDER BY sort_order, lastpost DESC



Thanks i never knew there was such a thing as a union! I will give it a try!

birdbrain24
07-13-2007, 04:24 PM
Why don't you use one query to retrieve all three types of threads? You could simply use a union to force them sorted the way you want...



SELECT blah, 1 as sort_order
FROM blah
WHERE type = 'IMPORTANT'
UNION ALL
SELECT blah, 2 as sort_order
FROM blah
WHERE type = 'STICKY'
UNION ALL
SELECT blah, 3 as sort_order
FROM blah
WHERE type = 'NORMAL'
ORDER BY sort_order, lastpost DESC


Thanks they are sorted in the right oreder going to try to add page numbering now i will keep you updated on my progress in case i may still need help with this lol if it don't work!

birdbrain24
07-13-2007, 04:41 PM
Thank GOD!

I Got It Working I Would Like To Thank Everyone For Their Help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum