Jump to content

new page guestbook in div without reload whole website


bernardmoes

Recommended Posts

i've written a code which reads Data from a database and shows it in a div

here the code:

 

<div id = "guestbookcontent">
<!-- Start guestbook div-->

<?php



$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysqlerror());
}
$db_selected = mysql_select_db('gastenboek', $link);
if(!db_selected) {
die ('Can\'t use weblog : ' . mysqlerror());
}

$result = mysql_query('SELECT * FROM guestbook ORDER BY bericht_id DESC');
if(!$result) {
die('Invalid query : ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result)) { 
echo "<i>". $row["timestamp"]. "</i>, ";
echo "<b>". $row["titel"] . "</b><br>";
echo $row["bericht"];
echo "<hr>";
}

?>
<!-- End of guestbook div -->
</div>

 

 

 

This code reads Data from my database.

now i want to show only 7 guestbook messages at once

so i wanted to be able to switch pages

i did this before and used this code:

 

$aantal = mysql_num_rows($result);
$perpage = 5; 
$page_count = ceil($aantal/$perpage); 
$page = (isset($_GET['page'])) ? $_GET['page'] : 1; 
$start = ($page * $perpage) - $perpage; 
$sql = "SELECT * FROM berichten ORDER BY bericht_id DESC LIMIT ".$start.",".$perpage.""; 
if ($page > 1) {
$Previous = $page-1; 
echo("<tr><td align = 'left'><a href='gastenboekframe.php?page=".$Previous."'>Previous</a></td>"); 
} else
{
echo("<tr><td align = 'left'><b>Previous</b></td>"); 
}
if ($page < ceil($aantal/$perpage)) 
{
$Next = $page+1;
echo("<td align = 'right'><a href='gastenboekframe.php?page=".$Next."'>Next</a></td></tr>");
}
else
{
echo("<td align = 'right'><b>Next</b></td></tr>");
} 

 

but now i want to change a guestbook page without reloading the whole page. I only want the div to reload, not the whole page.

thank you if you want to help me

 

 

 

If you want to change a part of the page without reloading the whole thing use AJAX. I use jquery for that:

http://api.jquery.com/category/ajax

it can be as simple as:

 

$('#guestbookcontent').load('myPagingScript.php?page=2');

 

attach that to the 'Next' link.

please help me because if i attach :

$('#guestbookcontent').load('myPagingScript.php?page=2');

 

to the link it doesnt work, if i do that then it looks like this:

<a href = "$('#guestbookcontent').load('index.php?page=".$volgende."');">Volgende</a>

 

it doesnt work

i have no idea how to attach that piece of code to my link

please tell me how to

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.