big pagination problem in php


Posted on 16th Feb 2014 07:03 pm by admin

<?php

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("guest") or die(mysql_error());
Did you know?Explore Trending and Topic pages for more stories like this.

function bbcode($string)
{
if ($string) {
$bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
'[/code]', '[img]http://', '[/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'm having a problem with the next row of results. They wont show...
No comments posted yet

Your Answer:

Login to answer
225 Like 29 Dislike
Previous forums Next forums
Other forums

Grabbing Values From an Array for Posting
I have a grid array that I am using with a form that when it hits the currently named test.php it lo

Display thumbnails as square while retaining aspect ratio
I am trying to figure out a way to make an image display as a square, for example 80x80 pixels, when

login form can you find my error?
registrationform.php seems fine send data to registration.php
registration.php seems fine checks

Material Issuing for receiving batch
Dear All experts in MM/ PP,

Material issuing from main stores to factory is currently usi

Form errors in an array
I'm processing a form and putting the errors in an array. empty($errors) doesn't seem to do the tric

user validation always displaying invalid ? please help
Hello,

I have 2 accounts and there is a field in mysql called validated it can be either &quo

How to Create a Dynamic table
col1 col2 date1 date2 date3 date4..........
a b v1 v2 v3 v4

button help
i originally had this but realised it is much easier to have a button.

Code: <?php

How to use Ajax to verify data on a DB ?
Hello everyone, well i want to know how to check a value if it exists or not on a Data base and capt

Gridview Not updating in Update Panel
I have a gridview, three dropdown list boxes, and a button on my form. What is displayed in the gri

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash