Russia Posted November 3, 2009 Share Posted November 3, 2009 I have added it: <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = false; } </script> <?php include("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM accounts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: ".mysql_error()); } } } echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Username</th> <th align=\"center\" scope=\"col\">Password</th> <th align=\"center\" scope=\"col\">Highscores</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> <th align=\"center\" scope=\"col\">Status</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(""); while($info = mysql_fetch_array( $data_p )) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['username'] . "</td>"; echo "<td class=\"valid\" >" . $info['password'] . "</td>"; echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>"; echo "<td>" . $info['addeddate'] . "</td>"; echo "<td>" . $info['ip'] . "</td>"; echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> "; echo " | "; echo " "; $previous = $pagenum-1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> "; } ?> Basically when you view the page and view the source the code stops at <form name = 'myform' action='' method='post'> so it cuts of everything under it, like the footer and some other things. That only happens when there are no records in the table, when there are the web page loads full working. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/ Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 On your mysql query (data_p) instead of die("") use die(mysql_error()) and post the error. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950398 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Okay I am getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4,4' at line 1 This is the updated code: <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = false; } </script> <?php include("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM accounts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: ".mysql_error()); } } } echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Username</th> <th align=\"center\" scope=\"col\">Password</th> <th align=\"center\" scope=\"col\">Highscores</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> <th align=\"center\" scope=\"col\">Status</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['username'] . "</td>"; echo "<td class=\"valid\" >" . $info['password'] . "</td>"; echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>"; echo "<td>" . $info['addeddate'] . "</td>"; echo "<td>" . $info['ip'] . "</td>"; echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> "; echo " | "; echo " "; $previous = $pagenum-1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> "; } ?> What seems to be the problem? Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950402 Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 Limits on queries must be within a positive range. You need to first check if your $pagenum exists. So doing something like $data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $max_pages = ceil($rows/$page_rows); $page = (int) $_GET['pagenum']; $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; that should do it. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950408 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Okay instead of what lines do I switch for the code u provided me? Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950411 Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 The lines in between where you echo your form introduction and the variable max definition. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950413 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Okkkaay, so these lines?? $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; Put this instead: $data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $max_pages = ceil($rows/$page_rows); $page = (int) $_GET['pagenum']; $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950416 Share on other sites More sharing options...
marcus Posted November 3, 2009 Share Posted November 3, 2009 Keep the $max line, but replace everything else. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950417 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Is this correct? <?php include("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM accounts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: ".mysql_error()); } } } echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Username</th> <th align=\"center\" scope=\"col\">Password</th> <th align=\"center\" scope=\"col\">Highscores</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> <th align=\"center\" scope=\"col\">Status</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; $data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $max_pages = ceil($rows/$page_rows); $page = (int) $_GET['pagenum']; $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['username'] . "</td>"; echo "<td class=\"valid\" >" . $info['password'] . "</td>"; echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>"; echo "<td>" . $info['addeddate'] . "</td>"; echo "<td>" . $info['ip'] . "</td>"; echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> "; echo " | "; echo " "; $previous = $pagenum-1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> "; } ?> The footer is now showing up but now under the table it has this: 1 | 2 | Last Even tho there are no records? Here is a picture: Also, now the pagination doesnt work, I click on page 2 when there are records and it wont show the list of accounts on page 2... Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950423 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Also, now the pagination doesnt work, I click on page 2 when there are records and it wont show the list of accounts on page 2... Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950430 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Okay I got it to show no pages when there is no records in the database. And I also got it to show when there are records in the database to show pages. But now the pages dont work. When I click to go to page 2 it shows the first 4 records from page 1. <?php include("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM accounts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: ".mysql_error()); } } } echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Username</th> <th align=\"center\" scope=\"col\">Password</th> <th align=\"center\" scope=\"col\">Highscores</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> <th align=\"center\" scope=\"col\">Status</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; $data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $max_pages = ceil($rows/$page_rows); $page = (int) $_GET['pagenum']; $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; $last = ceil($rows/$page_rows); $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['username'] . "</td>"; echo "<td class=\"valid\" >" . $info['password'] . "</td>"; echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>"; echo "<td>" . $info['addeddate'] . "</td>"; echo "<td>" . $info['ip'] . "</td>"; echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> "; echo " | "; echo " "; $previous = $pagenum-1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950433 Share on other sites More sharing options...
Russia Posted November 3, 2009 Author Share Posted November 3, 2009 Bump. Link to comment https://forums.phpfreaks.com/topic/180157-limit-function-problem-cutoff/#findComment-950448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.