PHP/SQL - Pagination help

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.

Localhost: http://i.imgur.com/COqcmHD.png

Webhost: http://i.imgur.com/KYxhAHY.png

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:
[php]

<?php error_reporting(1); session_start(); ?> <?php require_once 'include/incl_db.php'; ?> <?php require_once 'functions/functions.php'; ?> <?php function myAutoloader($class) { $class = strtolower($class); require_once $class . '.php'; } spl_autoload_register('myAutoloader'); ?> eShooting.dk - Nyheder <?php require_once 'include/modal_login.php'; ?>
<?php require_once 'include/menu.php'; ?>

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 "
"; echo "
"; echo ""; echo "
"; echo "
"; echo "

"; echo substr ($row['title'] , 0, 18) . "..."; echo "

"; echo "
"; echo "
"; echo "

"; echo substr ($row['tekst'] , 0, 38) . "....."; echo "

"; echo "
"; echo "
"; echo "

"; echo "D. "; echo date('d-m-Y', strtotime($row['dato'])); echo "

"; echo "
"; echo "
"; echo "Læs mere"; echo "
"; echo "
"; }; ?> <?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 "
".'First Page'." "; // Going to prev page echo "".'Prev Page'.""; // All Pages for ($i=1; $i<=$total_pages; $i++) { echo "".$i." "; }; // Going to next page echo "".'Next Page'.""; // Going to last page echo "".'Last Page'."
"; ?>

Sponsorer / Partnere!

Social!

<?php $sql = "SELECT * FROM es_sponsorer ORDER BY id ASC"; $res = $objCon->query($sql); while ($row = $res-> fetch_array()) { echo ''.$row['; } ?>
<?php $sql = "SELECT * FROM es_scoial ORDER BY id ASC"; $res = $objCon->query($sql); while ($row = $res-> fetch_array()) { echo ''.$row['; } ?>

Copyright © <?php $datetime = new DateTime(); echo $datetime->format('Y'); ?> eShooting.dk All Rights Reserved

[/php]

I hope you guys can help whit my problem, since i cant figure it out.

Best Regrads
Kevin P

Your query fails on the server. My guess is, you probably forgot to migrate the server structure over OR you didn’t change the credentials for them?

Im not quite sure what you mean astonecipher, i copied all the tables from my local database, to my online database, is it in my mysql the error lies ?

Looks like you may be using PDO?

Set the flags for it to throw exceptions and wrap the statement in a try catch.

[php]// set exception throwing
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try {
// query and execute code goes here
} catch (PDOException $e) {
echo $e->getMessage();
}[/php]

So you want me to do like this ?

[php]

<?php error_reporting(1); session_start(); ?> <?php require_once 'include/incl_db.php'; ?> <?php require_once 'functions/functions.php'; ?> <?php function myAutoloader($class) { $class = strtolower($class); require_once $class . '.php'; } spl_autoload_register('myAutoloader'); ?> eShooting.dk - Nyheder <?php require_once 'include/modal_login.php'; ?>
<?php require_once 'include/menu.php'; ?>

Nyheder!

<?php // set exception throwing $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                 try {
                     $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);
                    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>";
                    };
                    //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>";

                 }
                catch (PDOException $e) {
                    echo $e->getMessage();
                }
            ?>
        </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>
[/php]

Essentially yes. However, this

[php]$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);[/php]

should be in your database file, and should reference your pdo object.

Sponsor our Newsletter | Privacy Policy | Terms of Service