FrozenTears Posted June 26, 2009 Share Posted June 26, 2009 Fatal error: Call to a member function getPageNav() on a non-object in on line 102 Code From Line 102 <?php echo($rs2->getPageNav("val=$val&cat=$cat"))?> Function getPageNav Code (in function file) <?php class MySQLPagedResultSet { var $results; var $pageSize; var $page; var $row; function MySQLPagedResultSet($query,$pageSize,$cnx) { $resultpage = $_GET['resultpage']; $this->results = @mysql_query($query,$cnx); $this->pageSize = $pageSize; if ((int)$resultpage <= 0) $resultpage = 1; if ($resultpage > $this->getNumPages()) $resultpage = $this->getNumPages(); $this->setPageNum($resultpage); } function getNumPages() { if (!$this->results) return FALSE; return ceil(mysql_num_rows($this->results) / (float)$this->pageSize); } function setPageNum($pageNum) { if ($pageNum > $this->getNumPages() or $pageNum <= 0) return FALSE; $this->page = $pageNum; $this->row = 0; mysql_data_seek($this->results,($pageNum-1) * $this->pageSize); } function getPageNum() { return $this->page; } function isLastPage() { return ($this->page >= $this->getNumPages()); } function isFirstPage() { return ($this->page <= 1); } function fetchArray() { if (!$this->results) return FALSE; if ($this->row >= $this->pageSize) return FALSE; $this->row++; return mysql_fetch_array($this->results); } function getPageNav($queryvars = '') { $nav = ''; if (!$this->isFirstPage()) { $nav .= "<a href=\"?resultpage=". ($this->getPageNum()-1).'&'.$queryvars.'">Prev</a> '; } if ($this->getNumPages() > 1) for ($i=1; $i<=$this->getNumPages(); $i++) { if ($i==$this->page) $nav .= "$i "; else $nav .= "<a href=\"?resultpage={$i}&". $queryvars."\">{$i}</a> "; } if (!$this->isLastPage()) { $nav .= "<a href=\"?resultpage=". ($this->getPageNum()+1).'&'.$queryvars.'">Next</a> '; } return $nav; } } ?> $rs2 if needed (its in seprate file) <?php if($val==2 and $des!= ""){ //echo("<br><Br>------------------------------------------------<br>"); $mainQuery1="select * from poetry where id=".$des; $rs2 = new MySQLPagedResultSet($mainQuery1,50,$db_connection); $row14 = $rs2->fetchArray(); ?> well i dont know much about coding please reply with changes if possible i dont know hot to use isset() or is_object() Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/ Share on other sites More sharing options...
dzelenika Posted June 26, 2009 Share Posted June 26, 2009 put print_r($rs2); before echo($rs2->getPageNav("val=$val&cat=$cat")) you will see that $rs2 is not object Supposedly <?php if($val==2 and $des!= ""){ //echo("<br><Br>------------------------------------------------<br>"); $mainQuery1="select * from poetry where id=".$des; $rs2 = new MySQLPagedResultSet($mainQuery1,50,$db_connection); $row14 = $rs2->fetchArray(); ?> is never executed you can check this by uncommenting: //echo("<br><Br>------------------------------------------------<br>"); if <br><Br>------------------------------------------------<br> is not shown then your object is not created Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-864085 Share on other sites More sharing options...
FrozenTears Posted June 26, 2009 Author Share Posted June 26, 2009 not solved please help me to sort it out Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-864321 Share on other sites More sharing options...
SetToLoki Posted June 26, 2009 Share Posted June 26, 2009 class MySQLPagedResultSet { $rs2 = new MySQLPagedResultSet($mainQuery1,50,$db_connection); you are passing variables to this class when you haven't said it needs them Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-864338 Share on other sites More sharing options...
SetToLoki Posted June 26, 2009 Share Posted June 26, 2009 sorry my bad didn't read your code properly foget I spoke class MySQLPagedResultSet { var $results; var $pageSize; var $page; var $row; function MySQLPagedResultSet($query,$pageSize,$cnx) { to class MySQLPagedResultSet { public $results; public $pageSize; public $page; public $row; public function __construct($query,$pageSize,$cnx) { Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-864342 Share on other sites More sharing options...
FrozenTears Posted June 26, 2009 Author Share Posted June 26, 2009 code replaced as you said same error showing Link to comment https://forums.phpfreaks.com/topic/163762-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-864345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.