1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with Warning: mysql_fetch_assoc() expects parameter...

Discussion in 'PHP' started by granGripau, Oct 13, 2009.

  1. #1
    Hi all,

    I'm trying to build a pagination system, in place of my pagination showing up I get this warning:

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\cms sci\index.php on line 222

    this references line #8 below:

    1 <?php
    2 include('pagin.php');
    3 $conn = mysql_connect('xxxxx', 'xxxxx', 'xxxxx');
    4 mysql_select_db('cms_sci',$conn);
    5 $sql = 'select title from pages';
    6 $pager = new pagin($conn, $sql, 7, 2, 'param1=valu1&param2=value2');
    7 $rs = $pager->paginate();
    8 while($row = mysql_fetch_assoc($rs)) {
    9 echo $row['title'];
    10 }
    11 echo $pager->renderFullNav();
    12 ?>

    I know that I'm correctly connecting to Mysql because my dynamic content is coming through...

    Any suggestions?

    Thanks
     
    granGripau, Oct 13, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'd need to show the pager->paginate() method for us to be able to help you..
     
    premiumscripts, Oct 13, 2009 IP
  3. granGripau

    granGripau Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi premiumscripts,

    Thanks for responding!


    you mean this?:
    (sorry I'm just learning, aka please don't flog me if this isn't what you were asking for)

    <?php

    function paginate() {

    if (! $this->conn || ! is_resource($this->conn )) {
    if ($this->debug)
    echo "Error<br />";
    return false;
    }
    $all_rs = @mysql_query($this->sql );
    if (! $all_rs) {
    if ($this->debug)
    echo "Error: " . mysql_error();
    return false;
    }
    $this->total_rows = mysql_num_rows($all_rs );
    @mysql_close($all_rs );

    if ($this->total_rows == 0) {
    if ($this->debug)
    echo "Error.";
    return FALSE;
    }
    $this->max_pages = ceil($this->total_rows / $this->rows_per_page );
    if ($this->links_per_page > $this->max_pages) {
    $this->links_per_page = $this->max_pages;
    }
    if ($this->page > $this->max_pages || $this->page <= 0) {
    $this->page = 1;
    }
    $this->offset = $this->rows_per_page * ($this->page - 1);
    $rs = @mysql_query($this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}" );
    if (! $rs) {
    if ($this->debug)
    echo "Error: " . mysql_error();
    return false;
    }
    return $rs;
    }

    ?>
     
    granGripau, Oct 13, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Add

    $pager->debug = true;
    PHP:
    before $rs = ..
     
    premiumscripts, Oct 13, 2009 IP
  5. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Add a extra IF condition before while loop
    like,
    if($rs){
    while($row = mysql_fetch_assoc($rs)) {
    .
    .
    .
    }
    }

    This will filter the FALSE from the function to the mysql_fetch_assoc.

    BEc.What i feel is mysql_fetch_assoc(FALSE) will result in error ,Right?
     
    vetrivel, Oct 13, 2009 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There is a problem with your query or your connection. if you echo mysql_error() it should help to find out what is wrong
     
    JAY6390, Oct 13, 2009 IP