EazYKevin Posted March 13, 2017 Share Posted March 13, 2017 Hello Guys I Have been working on this site of mine for quite some time now, and just uploaded til to my webhost. then i get this error on my pagination, that i dont quite understand, so i hope you guys can help me, because its works perfectly fine on my localhost, i have the complete same database whit all the same information in the tables Localhost: Webhost: Error Code: Fatal error: Uncaught Error: Call to a member function fetch_array() on boolean in /var/www/eshooting.dk/public_html/nyheder.php:91 Stack trace: #0 {main} thrown in /var/www/eshooting.dk/public_html/nyheder.php on line 91 My Complete PHP File: <!-- Session --> <?php error_reporting(1); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- Meta Tags --> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- Database Include --> <?php require_once 'include/incl_db.php'; ?> <!-- Functions --> <?php require_once 'functions/functions.php'; ?> <!-- Classes --> <?php function myAutoloader($class) { $class = strtolower($class); require_once $class . '.php'; } spl_autoload_register('myAutoloader'); ?> <!-- GET --> <!-- Title --> <title>eShooting.dk - Nyheder</title> <!-- Css --> <link href="css/style.css" type="text/css" rel="stylesheet"> <link href="css/font-awesome.min.css" type="text/css" rel="stylesheet"> <!-- Fonts --> <link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'> <!-- Favicon --> <link rel="icon" href="img/csgo.png" type="image/x-icon"/> <link rel="shortcut icon" href="img/csgo.png" type="image/x-icon"/> <!-- jQuery --> <script src="js/jquery-1.11.1.min.js"></script> <script src="js/jquery-2.1.1.min.js"></script> </head> <body> <!-- Modal Login --> <?php require_once 'include/modal_login.php'; ?> <div id="container"> <div id="wrapper"> <div id="logo"> <a href="index.php"><img src="img/logo.png" /></a> </div> <?php require_once 'include/menu.php'; ?> <div id="content"> <div id="contenttitle"> <h1>Nyheder!</h1> </div> <div id="nyheder"> <?php $per_page=5; if (isset($_GET["page"])) { $page = $_GET["page"]; $prev = $page - 1; $next = $page + 1; } else { header('location:nyheder.php?page=1'); } // Page will start from 0 and Multiple by Per Page $start_from = ($page-1) * $per_page; //Selecting the data from table but with limit $sql = "SELECT * FROM es_nyheder LIMIT $start_from, $per_page"; $res = $objCon->query($sql); ?> <?php while ($row = $res-> fetch_array()) { $id = $row['id']; echo "<div class='nyhed2'>"; echo "<div class='nyhedimg2'>"; echo "<img src='img/csgo.png' />"; echo "</div>"; echo "<div class='nyhedtitle2'>"; echo "<h3>"; echo substr ($row['title'] , 0, 18) . "..."; echo "</h3>"; echo "</div>"; echo "<div class='nyhedtext2'>"; echo "<p>"; echo substr ($row['tekst'] , 0, 38) . "....."; echo "</p>"; echo "</div>"; echo "<div class='nyheddato2'>"; echo "<p>"; echo "D. "; echo date('d-m-Y', strtotime($row['dato'])); echo "</p>"; echo "</div>"; echo "<div class='nyhedmere2'>"; echo "<a href='nyhed2.php?id=$id'>Læs mere</a>"; echo "</div>"; echo "</div>"; }; ?> <?php //Now select all from table $sql = "SELECT * FROM es_nyheder"; $res = mysqli_query($objCon, $sql); // Count the total records $total_records = mysqli_num_rows($res); //Using ceil function to divide the total records on per page $total_pages = ceil($total_records / $per_page); //Going to first page echo "<div id='paginationcenter'><div id='pagination'><a href='nyheder.php?page=1'>".'First Page'."</a> "; // Going to prev page echo "<a href='nyheder.php?page=$prev'>".'Prev Page'."</a>"; // All Pages for ($i=1; $i<=$total_pages; $i++) { echo "<a "; if($page == $i){ echo "class='currentpage'"; } echo " href='nyheder.php?page=".$i."'>".$i."</a> "; }; // Going to next page echo "<a href='nyheder.php?page=$next'>".'Next Page'."</a>"; // Going to last page echo "<a href='nyheder.php?page=$total_pages'>".'Last Page'."</a></div></div>"; ?> </div> </div> </div> <div id="scoial"> <div id="scoialtitle1"> <h2>Sponsorer / Partnere!</h2> </div> <div id="scoialtitle2"> <h2>Social!</h2> </div> <div id="sponsorer"> <?php $sql = "SELECT * FROM es_sponsorer ORDER BY id ASC"; $res = $objCon->query($sql); while ($row = $res-> fetch_array()) { echo '<a href="'.$row["hjemmeside"].'"><img src="img/sponsor-partner/'.$row["billede"].'" alt="'.$row["navn"].'" /></a>'; } ?> </div> <div id="scoiale"> <?php $sql = "SELECT * FROM es_scoial ORDER BY id ASC"; $res = $objCon->query($sql); while ($row = $res-> fetch_array()) { echo '<a href="'.$row["hjemmeside"].'"><img src="img/social/'.$row["billede"].'" alt="'.$row["navn"].'" /></a>'; } ?> </div> </div> <div id="footer"> <p>Copyright © <?php $datetime = new DateTime(); echo $datetime->format('Y'); ?> eShooting.dk All Rights Reserved</p> </div> </div> </div> </body> </html> I hope you guys can help whit my problem, since i cant figure it out. Best Regrads Kevin P Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/ Share on other sites More sharing options...
mac_gyver Posted March 13, 2017 Share Posted March 13, 2017 start by setting error_reporting to E_ALL. by setting it to a 1, the only errors that are being reported are fatal runtime errors. Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544181 Share on other sites More sharing options...
ginerjm Posted March 13, 2017 Share Posted March 13, 2017 All that code posted but so little of it is actually PHP. Do you do tests on your connection results and db select results? You don't do it on your query results so there are several possibilities for failure right there. Also - echo out your query statement before executing it to be sure you have it setup correctly. A good design practice is to completely separate the bulk of your html code from the php code and perform the latter first. Build your dynamic content into php vars and place them within the static html and only THEN do your output. Makes for a more readable (and understandable) script which also becomes easier to modify and to maintain as time goes by. Comments help to. Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544182 Share on other sites More sharing options...
EazYKevin Posted March 13, 2017 Author Share Posted March 13, 2017 for some wierd reson i wouldnt exec my if statement in my code, and said the headers have allready been sent, so i jump the if to the the top of my code, and now it works again Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544189 Share on other sites More sharing options...
ginerjm Posted March 13, 2017 Share Posted March 13, 2017 Uh.... Weird and Reason would be the words you were looking for. Happy you solved your problem, whatever it was and whatever you did. Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544191 Share on other sites More sharing options...
EazYKevin Posted March 13, 2017 Author Share Posted March 13, 2017 thank, you guys for trying to help me Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544192 Share on other sites More sharing options...
ginerjm Posted March 13, 2017 Share Posted March 13, 2017 The reason for that error message? You can't issue a 'header()' command once you have already done ANY output to your client. Even an inadvertent space char at the beginning of a line of code outside of php mode would do it. Usually headers are issued only in php mode before you get to the point of issuing any html for that reason. Quote Link to comment https://forums.phpfreaks.com/topic/303447-phpsql-pagination-help/#findComment-1544194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.