Hi guys need some extra help/eye here to point out what am i doing wrong

basically i want to display the data from mydbase.by the way the purpose of this page is for posting article anyway what im trying to do is put a Next and previous navigation bar but it seems that even in displaying the data is not working any dea how to do it?

here's the complete code with the necessary changes (original code by himerus)

<?php
$server = "localhost";
$user = "root";
$pass = "";
$databasename = "mydatabase";
$db = mysql_connect($server, $user, $pass);
    mysql_select_db($databasename,$db);

        $sql = "SELECT * FROM php_blog ";
        $query = mysql_query($sql,$db);
        $total_results = mysql_num_rows($query);
        $limit = "15"; //limit of archived results per page.
        $total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
    {
        $page = "1"; //default page if none is selected
    }
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB

    $query = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 3 $offset, $limit";
    $result = mysql_query($query);
//This is the start of the normal results...

    while ($row = mysql_fetch_array($result))
        {

    $date = date("l F d Y", $row['timestamp']);

    $title = stripslashes($row['title']);
    $author = stripslashes($row['author']);
    $cat = stripslashes($row['category']);
    $intro = stripslashes($row['intro']);
        }
        mysql_close();


// This is the Previous/Next Navigation
echo "<font face=Verdana size=1>";
echo "Pages:($total_pages)&nbsp;&nbsp;"; // total pages
if ($page != 1)
{
echo "<a href=$PHP_SELF?page=1><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
$prevpage = $page - 1;
echo "&nbsp;<a href=$PHP_SELF?page=$prevpage><<</a>&nbsp;"; // Previous Page Link
}
        if ($page == $total_pages) 
            {
                $to = $total_pages;
            } 
        elseif ($page == $total_pages-1) 
            {
                $to = $page+1;
            } 
        elseif ($page == $total_pages-2) 
            {
                $to = $page+2;
            } 
        else 
            {
                $to = $page+3;
            }
        if ($page == 1 || $page == 2 || $page == 3) 
            {
                $from = 1;
            } 
        else 
            {
                $from = $page-3;
            }

for ($i = $from; $i <= $to; $i++)

    {
    if ($i == $total_results) $to=$total_results;
    if ($i != $page)
        {
        echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
        }
    else
        {
        echo "<b><font face=Verdana size=2>[$i]</font></b>";
        }
    if ($i != $total_pages)
        echo "&nbsp;";
    }
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo "&nbsp;<a href=$PHP_SELF?page=$nextpage>>></a>&nbsp;"; // Next Page Link
echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link
}
echo "</font>";

?>

and also this is the error that im getting

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\unlimusic_v11 Oct 13 2012\secured\test.php on line 24

Pages:(1) [1]

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\unlimusic_v11 Oct 13 2012\secured\test.php on line 24

Line 24 is this:

while ($row = mysql_fetch_array($result))

Your mysql_fetch_array() can't fetch the $result because

on Line 21 is this:

$result = mysql_query($query);

Your mysql_query() is not getting $query because

on Line 20 is this:

$query = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 3 $offset, $limit";

It means that you can't connect to the database correctly because there's something wrong with your query!

You need to fixed your query in order for it to work.

**@LastMitch ** still cant get it could you tell me what part of the query should i need to change?

here's the error

Can't select entries from table php_blog.
SELECT * FROM php_blog
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 '0, 15' at line 1
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\unlimusic_v11 Oct 13 2012\secured\test.php on line 24
Pages:(1) [1]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.