Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


big pagination problem in php

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Tue Oct 13, 2009 8:00 am    Post subject: big pagination problem in php Reply with quote

Code:
<?php

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("guest") or die(mysql_error());

function bbcode($string)
{
    if ($string) {
        $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
            '[/code]', '[img]', '[/img]');
        $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>',
            '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">',
            '</div></center>', '<img src="', '">');

        $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string);

        return $new_string_2;
    }
}

echo "<h1>Guestbook</h1><hr />";

$queryget = mysql_query("SELECT * FROM guest ORDER BY id DESC") or die(mysql_error
    ());

$querygetrownum = mysql_num_rows($queryget);

if ($querygetrownum == 0) {
    echo "No posts have been made yet! Be the first!";
}

$per_page = 5;

$start = $_GET['start'];

$record_count = mysql_num_rows(mysql_query("SELECT * FROM guest"));

$max_pages = $record_count / $per_page;

if (!$start) {
    $start = 0;

    $get = mysql_query("SELECT * FROM guest ORDER BY id DESC LIMIT $start, $per_page");

    while ($row2 = mysql_fetch_assoc($get)) {
        $name2 = $row2['name'];
        $email2 = $row2['email'];
        $message2 = $row2['message'];
        $date2 = $row2['date'];
        $time2 = $row2['time'];
        echo "<table><tr><td><b>Posted by: " . $name2 . "(" . $email2 . ") on " . $date2 .
            " at " . $time2 . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags($message2))) .
            "</td></tr></table>";
        echo "<hr />";
    }
}
    //setup prev and next variables
    $prev = $start - $per_page;
    $next = $start + $per_page;

    //show prev button
    if (!($start <= 0)){
        echo "<a href='index.php?start=$prev'>Prev</a> ";
   }else{
      echo "&laquo; Prev";
   }
    //show page numbers

    //set variable for first page
    $i = 1;

    for ($x = 0; $x < $record_count; $x = $x + $per_page) {
        if ($start != $x){
            echo " <a href='index.php?start=$x'>$i</a> ";
        }else{
            echo " <a href='index.php?start=$x'><b>$i</b></a> ";
        }
        $i++;
    }

    //show next button
    if (!($start >= $record_count - $per_page)){
        echo " <a href='index.php?start=$next'>Next</a>";
   }else{
      echo "Next &raquo;";
   }
    if ($_POST['submit']) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $date = date("Y-m-d");
        $time = date("H:i:s");

        if ($name && $email && $message) {
            $querypost = mysql_query("INSERT INTO guest VALUES('','" . $name . "','" . $email .
                "','" . $message . "','" . $date . "','" . $time . "')");
            echo "Please wait... <meta http-equiv='refresh' content='2'>";
        } else {
            echo "Please fill out all fields!";
        }
    }

    echo "<hr />";

    echo "
    <form action='index.php' method='POST'>

    <table width='100%'>

    <tr>

    <td width='7%' valign='top'>
    Your Name:
    </td>

    <td valign='top'>
    <input type='text' name='name' maxlength='25' />
    </td>

    </tr>

    <tr>

    <td valign='top'>
    Your Email:
    </td>

    <td>
    <input type='text' name='email' maxlength='25' />
    </td>

    </tr>

    <tr>

    <td valign='top'>
    Your Message:
    </td>

    <td>
    <textarea cols='20' rows='2' name='message' maxlength='250'></textarea>
    <p><input type='submit' name='submit' value='Post' />
    </td>

    </tr>
    </table>

    </form>";

?>

<style type="text/css">
body{font-family:Arial;font-size:14px;background-image: url('./images/bg.png');color:#FFFF00;}h1{font-family:Arial;}hr{color:#FFFF00; }a{color:#FFFFFF;text-decoration:none;}a:hover{color:#FFFFFF;text-decoration:underline;}
</style>



I am writing a single page guestbook for my bands website, but when i go to the next page in pagination, it doesn't seem to show the next set of results.
Back to top
View user's profile Send private message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Tue Oct 13, 2009 8:27 am    Post subject: Reply with quote

What you did wrong was (what I think) the LIMIT in the sql.

Code:
$per_page = 5;

$start = $_GET['start'];

$record_count = mysql_num_rows(mysql_query("SELECT * FROM guest"));

$max_pages = $record_count / $per_page;

if (!$start) {
    $start = 0;

    $get = mysql_query("SELECT * FROM guest ORDER BY id DESC LIMIT $start, $per_page");

    while ($row2 = mysql_fetch_assoc($get)) {
        $name2 = $row2['name'];
        $email2 = $row2['email'];
        $message2 = $row2['message'];
        $date2 = $row2['date'];
        $time2 = $row2['time'];
        echo "<table><tr><td><b>Posted by: " . $name2 . "(" . $email2 . ") on " . $date2 .
            " at " . $time2 . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags($message2))) .
            "</td></tr></table>";
        echo "<hr />";
    }
}
You want to show 5 posts per page, and $_GET['start'] as the page you want to view, am I correct? Looking at the source above you use LIMIT $start, $per_page.

But you are getting it from your post table in your sql database, which requires you to put it in the amount of posts instead of the page you want. So I suggest you use (if you use $start as the page number)
$start = $start * $per_page; (will get all the posts on page 5 (so 5*5 starting from post 25)
$limit = $start + $per_page; (Will stop looking for the post after you have 25 + 5, which is thirty)

Good luck!
Back to top
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Tue Oct 13, 2009 8:57 am    Post subject: Reply with quote

sorry, but i've got no clue what your on about, i can write the code, but i can't seem to understand most of it sometimes.
Back to top
View user's profile Send private message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Tue Oct 13, 2009 9:27 am    Post subject: Reply with quote

Nostrich wrote:
sorry, but i've got no clue what your on about, i can write the code, but i can't seem to understand most of it sometimes.
You write code you don't understand?

inb4c&p
Back to top
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Tue Oct 13, 2009 9:43 am    Post subject: Reply with quote

yes, i know it may sound retarded, but most of the time, it works, i was thinking about buying a book, but then i had to lend all my money to my sister because she wanted ANOTHER PS3...... Mad Mad Mad Mad Mad Mad Mad Mad Mad Mad Mad Mad Mad Mad
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites