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¶m2=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
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; } ?>
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?
There is a problem with your query or your connection. if you echo mysql_error() it should help to find out what is wrong