Page 1 of 1

Warning: mysql_result(): supplied argument is not a valid...

Posted: Wed Mar 17, 2004 4:07 pm
by akamattman
full error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /path/... on line 38
:?: :? :(
here is what i am trying to do...i want to add a paging system to my blog so that the page isnt 50 miles high...

here is what i have going on...

test.php:

Code: Select all

<?php
   include('dbconfig.php');

    $total = 130;  
    $limit = 20;  
    $page = 3;  
    $numPages = ceil($total / $limit);  
 
       function getPagerData($numPages, $limit, $page)  
       &#123;  
           $numPages  = (int) $numPages;  
           $limit    = max((int) $limit, 1);  
           $page     = (int) $page;  
           $numPages = ceil($numPages / $limit);  

           $page = max($page, 1);  
           $page = min($page, $numPages);  

           $offset = ($page - 1) * $limit;  

           $ret = new stdClass;  

           $ret->offset   = $offset;  
           $ret->limit    = $limit;  
           $ret->numPages = $numPages;  
           $ret->page     = $page;  

           return $ret;  
       &#125;  
 
  
    // get the pager input values 
    $page = $_GET&#1111;'page'];  
    $limit = 20;  
    $result = mysql_query("select count(*) from $entrytable");  
    $total = mysql_result($result, 0, 0); //******error line******

    // work out the pager values 
    $pager  = getPagerData($total, $limit, $page);  
    $offset = $pager->offset;  
    $limit  = $pager->limit;  
    $page   = $pager->page;  

    // use pager values to fetch data 
    $query = "select * from $entrytable order by someField limit $offset, $limit";  
    $result = mysql_query($query);  

    // use $result here to output page content  
?>

<table align="center" width="80%">
<td align="center" width="100%">
<?php echo "$result"; ?>
</td>
</table>

<?php
    // output paging system (could also do it before we output the page content) 
    if ($page == 1) // this is the first page - there is no previous page 
        echo "Previous";  
    else            // not the first page, link to the previous page 
        echo "<a href="test.php?page=" . ($page - 1) . "">Previous</a>";  

    for ($i = 1; $i <= $pager->numPages; $i++) &#123;  
        echo " | ";  
        if ($i == $pager->page)  
            echo "Page $i";  
        else  
            echo "<a href="test.php?page=$i">Page $i</a>";  
    &#125;  

    if ($page == $pager->numPages) // this is the last page - there is no next page 
        echo "Next";  
    else            // not the last page, link to the next page 
        echo "<a href="test.php?page=" . ($page + 1) . "">Next</a>";  
?>
dbconfig.php:

Code: Select all

<?php

 // MySQL database connection information
   $host          = "localhost";     // MySQL host
   $username      = "user";          // MySQL username
   $userpass      = "pass";          // MySQL password
   $database      = "myDB";       // MySQL database

 // MySQL database table information
   $entrytable    = "blog_post";     // MySQL table to hold blog entries
   $commenttable  = "blog_comm";     // MySQL table to hold comments
?>
now, of course those are not the actual values for the $username etc...but yeah...

so what gives? any help will be very helpful! (let me know if you need more info)

Thanks,
Matt

Posted: Wed Mar 17, 2004 4:45 pm
by pickle
1) Using the PHP tags rather than the CODE tags, colours the code for even easier reading :)
2) Change this line to help you find the problem exactly:

Code: Select all

/////////// ORIGINAL ///////////
$result = mysql_query("select count(*) from $entrytable");

/////////// NEW ///////////
$query = "SELECT COUNT(*) FROM $entrytable");
echo $query;
$result = mysql_query($query) or die(mysql_error());
Doing this will:
Help you see exactly what the query is and,
Help you see exactly what the MySQL error is.


The problem you're having is that an error is happening in MySQL resulting from line 37, but it doesn't manifest itself until line 38.

Posted: Wed Mar 17, 2004 4:48 pm
by akamattman
hey, thanks! i didnt even see the php tag..lol

well, im sure this isnt the last question ill have about this one thing (new to php and mySQL) but ill take ur advice and see what i can come up with

thanks again,
matt