bernardmoes Posted February 21, 2010 Share Posted February 21, 2010 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 Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/ Share on other sites More sharing options...
F00Baron Posted February 21, 2010 Share Posted February 21, 2010 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. Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/#findComment-1015699 Share on other sites More sharing options...
bernardmoes Posted February 22, 2010 Author Share Posted February 22, 2010 how can i attach that code to the next link? can you please tell me how? thank you for your reply Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/#findComment-1016062 Share on other sites More sharing options...
bernardmoes Posted February 22, 2010 Author Share Posted February 22, 2010 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 Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/#findComment-1016194 Share on other sites More sharing options...
bernardmoes Posted February 22, 2010 Author Share Posted February 22, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/#findComment-1016445 Share on other sites More sharing options...
bernardmoes Posted February 23, 2010 Author Share Posted February 23, 2010 anybody got an answer????? Link to comment https://forums.phpfreaks.com/topic/192823-new-page-guestbook-in-div-without-reload-whole-website/#findComment-1016693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.