mrdobalina Posted August 8, 2014 Share Posted August 8, 2014 <?php $con=mysqli_connect("address","username","pass","db name"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if (!(isset($pagenum))) { $pagenum = 1; } $data = mysqli_query($con,"SELECT * FROM info"); $rows = mysql_num_rows($data); $page_rows = 15; $last = ceil($rows/$page_rows); if($pagenum < 1); { $pagenum = 1; } elseif ($pagenum > $last); { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $result = mysql_query($con,"SELECT * FROM topsites $max") or die(mysql_error()); echo "<table border='1' class='boldtable' cellpadding='2'> <tr> <th>Creditor</th> <th>dd/mm/yyyy</th> <th>Credit Score</th> <th>State</th> <th>Income</th> <th>Approval</th> <th>Credit Line</th> <th>Interest</th> <th>Comment</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['creditor'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['fako'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['income'] . "</td>"; echo "<td>" . $row['approval'] . "</td>"; echo "<td>" . $row['creditline'] . "</td>"; echo "<td>" . $row['interest'] . "</td>"; echo "<td>" . $row['comments'] . "</td>"; echo "</tr>"; } echo "</table>"; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } mysqli_close($con); ?> All I want are the pages broken up into pages. It is going wrong somewhere before my table. Can someone help me out? Thank you! Link to comment https://forums.phpfreaks.com/topic/290344-help-with-page-number-where-am-i-going-wrong/ Share on other sites More sharing options...
mac_gyver Posted August 8, 2014 Share Posted August 8, 2014 the $pagenum variable doesn't exist. the ?pagenum parameter in the url would be available to the php code as $_GET['pagenum'] Link to comment https://forums.phpfreaks.com/topic/290344-help-with-page-number-where-am-i-going-wrong/#findComment-1487175 Share on other sites More sharing options...
cyberRobot Posted August 8, 2014 Share Posted August 8, 2014 Side note: using the raw value from PHP_SELF in anchor tags makes your script vulnerable to XSS attacks. http://www.cyberscorpion.com/2012-03/why-php_self-should-be-avoided-when-creating-website-links/ Link to comment https://forums.phpfreaks.com/topic/290344-help-with-page-number-where-am-i-going-wrong/#findComment-1487183 Share on other sites More sharing options...
mac_gyver Posted August 8, 2014 Share Posted August 8, 2014 It is going wrong somewhere before my table. in addition to what has already been mentioned, your code contains both the mysqli_ and mysql_ (no i) database functions (these cannot be mixed together on one database connection), so of course the code using the mysql_ (no i) functions is not working. you need to use all mysqli_ functions. Link to comment https://forums.phpfreaks.com/topic/290344-help-with-page-number-where-am-i-going-wrong/#findComment-1487186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.