Note that there are some explanatory texts on larger screens.

plurals
  1. POSome code works fine and sometime get Fatal error in mysql statement
    primarykey
    data
    text
    <p>Its a pagination code on php and mysql. I have include the same code in two pages (news and user) The code works fine in news where as in user page the code does works sometime but most of the time i get the wired error saying <code>"Fatal error: SQL in /Applications/MAMP/htdocs/NDFUND/admin/include/page.php on line 6".</code> </p> <p>Any help would be appreciated . The code is following which file name is page.php This page include 2 global variable which is define on news.php and user.php. one is $tbl_name and other is $rowsperpage</p> <pre><code>&lt;?php require_once('../Connections/ndConn.php'); $sql = "SELECT COUNT(*) FROM $tbl_name"; $result = mysql_query($sql, $ndConn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $totalpages = ceil($numrows / $rowsperpage); if (isset($_GET['currentpage']) &amp;&amp; is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } // end if if ($currentpage &gt; $totalpages) { $currentpage = $totalpages; } if ($currentpage &lt; 1) { $currentpage = 1; } // end if $offset = ($currentpage - 1) * $rowsperpage; $sql = "SELECT * FROM $tbl_name LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $ndConn) or trigger_error("SQL", E_USER_ERROR); $range = 2; if ($currentpage &gt; 1) { $pagination = " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=1'&gt;[ First ]&lt;/a&gt; "; $prevpage = $currentpage - 1; $pagination .= " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'&gt;[ &lt; ]&lt;/a&gt; "; } for ($x = ($currentpage - $range); $x &lt; (($currentpage + $range) + 1); $x++) { if (($x &gt; 0) &amp;&amp; ($x &lt;= $totalpages)) { if ($x == $currentpage) { $pagination .= " &lt;span class=\"selected\"&gt;[ $x ]&lt;/span&gt; "; } else { $pagination .= " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$x'&gt;[ $x ]&lt;/a&gt; "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; $pagination .= " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'&gt;[ &gt; ]&lt;/a&gt; "; $pagination .= " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'&gt;[ Last ]&lt;/a&gt; "; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload