imperialized Posted May 1, 2008 Share Posted May 1, 2008 Ok, so I am working on trying to make a working AJAX script. It works in the context that it executes the query, however the LIMIT is wrong. main page: <?php /** * @author David Lallone * @content AJAX/MYSQL submit/retrieve test * @copyright 2008 */ ?> <html> <head> </head> <body> This is a Form: <br> <form name="ajax" action="ajax_form.php?action=Submit&page=<?php echo $pg; ?>" METHOD="post"> <input name="name" type=text><br> <input name="message" type=text><br> <input type="submit" value="submit"> <script src="sortfilter.js"></script> <div id="content"> <br> <!-- This is where the JAVASCRIPT will display the data --!> <?php include("db_con.php"); $pg = $_GET['page']; if ($pg == "") { $pg = 1; $start=0; $end=16; } if ($pg == 1){ $start=0; $end=16; } else { $start = $pg * 16 - 15; $end = $pg * 16; } $next_pg = $pg+1; $prev_pg = $pg-1; //Submitting info to DB /* if($_GET['action'] == "Submit"){ $name = $_POST['name']; $message = $_POST['message']; $insert = "INSERT INTO ajax (name, message) VALUES ('$name', '$message')"; $insert_query = mysql_query($insert) OR DIE("Error: ". mysql_error()); include("db_con.php"); $query = "SELECT * FROM ajax LIMIT $start, $end"; $go = mysql_query($query); if(mysql_num_rows($go) != 0){ while($x = mysql_fetch_array($go)){ $name = $x['name']; $message = $x['message']; print "<b>$name</b>: $message <br>"; } } else { print "No Messages Have Been Left"; } } else { */ //Not Submitting info Print "Page: $pg Start: $start End: $end <br><br>"; $query = "SELECT * FROM ajax LIMIT $start, $end"; $go = mysql_query($query); $count = mysql_num_rows($go); if(mysql_num_rows($go) != 0){ while($x = mysql_fetch_array($go)){ $name = $x['name']; $message = $x['message']; print "<b>$name</b>: $message <br>"; } } else { print "No Messages Have Been Left"; } print "Total Results Returned: $count <br>"; Print " Next Button: <input type=button name='next' value='Next' onclick='Next($next_pg)'> "; // } ?> </div> :: page.php (exceuted using ajax) <?php /** * @author * @copyright 2008 */ include("db_con.php"); $pg = $_GET['page']; print "Page = $pg "; if ($pg == "") { $pg = 1; $start=0; $end=16; } if ($pg == 1){ $start=0; $end=16; } else { $start = $pg * 16 - 15; $end = $pg * 16; } $next_pg = $pg+1; $prev_pg = $pg-1; Print "Start: $start End: $end <br><br>"; $query = "SELECT * FROM ajax LIMIT $start, $end"; $go = mysql_query($query); $count = mysql_num_rows($go); if(mysql_num_rows($go) != 0){ while($x = mysql_fetch_array($go)){ $name = $x['name']; $message = $x['message']; print "<b>$name</b>: $message <br>"; } } else { print "No Messages Have Been Left"; } print "Total Results Returned: $count <br>"; Print " Next Button: <input type=button name='next' value='Next' onclick='Next($next_pg)'> "; ?> an example of this page can be found at: http://www.imperialized.net/ajax/ajax_form.php I have it set to display the $start and $end variables, and they are correct. But as you see, the page results vary for some reason. Link to comment https://forums.phpfreaks.com/topic/103680-ajaxphp-passing-variables-and-limiting-queries/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.