Foser Posted July 29, 2007 Share Posted July 29, 2007 I want my code to do a pagination. OOP file: paging.php <?php class Paging { var $GETPAGE; var $max_ammount; var $limit_db; var order_db; function Paging($GETPAGE,$max_ammount,$limit_db,$order_db){ if (!isset($GETPAGE) or $GETPAGE == 1){ $max_ammount; $min_value = 0; } if ($GETPAGE == 2) { $max_ammount; $min_value = $GETPAGE;} if ($GETPAGE > 2){ $max_ammount; $min_value = $getpage * $max_ammount - $max_ammount;} $db_limiter = mysql_query("SELECT * FROM {$limit_db} ORDER BY {$order_db} LIMIT $min_value , $max_value"); } function max_min_value(){ return $max_ammount; return $min_value } function limit_db(){ return $db_limiter; } } ?> code: <?php require('paging.php'); mysql_connect(localhost,root,password); mysql_select_db(tutorial1); $page_table = "pagination"; $db_order = "id"; $max_ammount = 4; $paging = new paging($_GET['page'],$max_ammount,$page_table,$db_order); $max_min = $paging->max_min_value(); while ($row_info = mysql_fetch_assoc($paging->limit_db())){ echo "ID Number: {$row_info['id']}<br>Name: {$row_info['name']}<br>Age: {$row_info['age']}<br>Referer: {$row_info['referer']}<br>-----------------------------------------------------<br>"; } ?> error if ($_GET['page'] > 2){ $getpage = $_GET['page']; $max_value = 2; $min_value = $getpage * 2 - 2;} $query2 = mysql_query("SELECT * FROM pagination ORDER BY id"); Fatal error: Call to undefined method Paging::max_min_value() in C:\WAMP\www\Tutorials\OOP_Testing\paging\index.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/ Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 function max_min_value(){ return $max_ammount; return $min_value } A return call is a sign for the function to end.... You can't use two returns like that; however, you could return the variables in an array or with a delimiter. Also, functions in classes, just like not in classes, have their own variable scope... To refer to a class' varialble, you should use the $this syntax. function max_min_value(){ return array($this->max_ammount, $this->min_value); } That also means that your other methods need some altercations: <?php class Paging { var $GETPAGE; var $max_ammount; var $limit_db; var $order_db; //dunno why, but your $ was missing var $min_value; //added this so you could use it class wide later var $this->db_limiter; //added for the same reason as min_value function Paging($GETPAGE,$max_ammount,$limit_db,$order_db){ //it looks like you're trying to use most of your variables in other methods, so you might as well assign them to class variables. $this->GETPAGE = $GETPAGE; $this->max_ammount = $max_ammount; $this->limit_db = $limit_db; $this->order_db = $order_db; if (!isset($GETPAGE) or $GETPAGE == 1){ //$max_ammount; //I'm not quite sure why you have this.... $this->min_value = 0; } if ($GETPAGE == 2) { $this->min_value = $GETPAGE; } if ($GETPAGE > 2){ $this->min_value = $getpage * $max_ammount - $max_ammount; } $this->db_limiter = mysql_query("SELECT * FROM {$limit_db} ORDER BY {$order_db} LIMIT $min_value , $max_value"); } function max_min_value(){ return array($this->max_ammount, $this->min_value); } function limit_db(){ return $this->db_limiter; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-310233 Share on other sites More sharing options...
Foser Posted July 31, 2007 Author Share Posted July 31, 2007 I still seem to have an error, I think im outputing it wrong... Seems to not think that there is a mysql query... error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\Tutorials\OOP_Testing\paging\index.php on line 9 output file (index.php) <?php require('paging.php'); mysql_connect(localhost,root,password); mysql_select_db(tutorial1); $page_table = "pagination"; $db_order = "id"; $max_ammount = 4; $paging_system = new paging($_GET['page'],$max_ammount,$page_table,$db_order); while ($row_info = mysql_fetch_assoc($paging_system->db_limiter)){ echo "ID Number: {$row_info['id']}<br>Name: {$row_info['name']}<br>Age: {$row_info['age']}<br>Referer: {$row_info['referer']}<br>-----------------------------------------------------<br>"; } ?> OOP Page: <?php class Paging { var $GETPAGE; var $max_ammount; var $limit_db; var $order_db; function Paging($GETPAGE,$max_ammount,$limit_db,$order_db){ $this->GETPAGE = $GETPAGE; $this->max_ammount = $max_ammount; $this->limit_db = $limit_db; $this->order_db; if (!isset($GETPAGE) or $GETPAGE == 1){ $this->min_value = 0; } if ($GETPAGE == 2) { $this->min_value = $GETPAGE;} if ($GETPAGE > 2){ $this->min_value = $getpage * $max_ammount - $max_ammount;} $this->db_limiter = mysql_query("SELECT * FROM {$limit_db} ORDER BY {$order_db} LIMIT $min_value , $max_value"); } function max_page_value(){ return $this->max_ammount; } function min_page_value(){ return $this->min_value;} function page_limit_db(){ return $this->db_limiter; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-311794 Share on other sites More sharing options...
Foser Posted July 31, 2007 Author Share Posted July 31, 2007 edited! error: Fatal error: Call to undefined method Paging::db_limiter() in C:\WAMP\www\Tutorials\OOP_Testing\paging\index.php on line 9 index.php <?php require('paging.php'); mysql_connect(localhost,root,password); mysql_select_db(tutorial1); $page_table = "pagination"; $db_order = "id"; $max_ammount = 4; $paging_system = new paging($_GET['page'],$max_ammount,$page_table,$db_order); while ($row_info = mysql_fetch_assoc($paging_system->db_limiter())){ echo "ID Number: {$row_info['id']}<br>Name: {$row_info['name']}<br>Age: {$row_info['age']}<br>Referer: {$row_info['referer']}<br>-----------------------------------------------------<br>"; } ?> OOP CODE: <?php class Paging { var $GETPAGE; var $max_ammount; var $limit_db; var $order_db; function Paging($GETPAGE,$max_ammount,$limit_db,$order_db){ $this->GETPAGE = $GETPAGE; $this->max_ammount = $max_ammount; $this->limit_db = $limit_db; $this->order_db; if (!isset($GETPAGE) or $GETPAGE == 1){ $this->min_value = 0; } if ($GETPAGE == 2) { $this->min_value = $GETPAGE;} if ($GETPAGE > 2){ $this->min_value = $getpage * $max_ammount - $max_ammount;} $this->db_limiter = mysql_query("SELECT * FROM {$limit_db} ORDER BY {$order_db} LIMIT $min_value , $max_value"); } function max_page_value(){ return $this->max_ammount; } function min_page_value(){ return $this->min_value;} function page_limit_db(){ return $this->db_limiter; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-311861 Share on other sites More sharing options...
lur Posted August 1, 2007 Share Posted August 1, 2007 You have no method called db_limiter(), you have a variable called $db_limiter and a method called page_limit_db() that returns $db_limiter. // using the variable, removed trailing parenthesis. while ($row_info = mysql_fetch_assoc($paging_system->db_limiter)){ // using the page_limit_db() method while ($row_info = mysql_fetch_assoc($paging_system->page_limit_db())){ Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-312877 Share on other sites More sharing options...
Foser Posted August 2, 2007 Author Share Posted August 2, 2007 I did the second one and still get an error! ??? Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\Tutorials\OOP_Testing\paging\index.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-313980 Share on other sites More sharing options...
Foser Posted August 4, 2007 Author Share Posted August 4, 2007 I don't think my limit variables ar eworking on my OOP Quote Link to comment https://forums.phpfreaks.com/topic/62318-my-oop-pagination-functions-arent-working-new-to-oop/#findComment-315438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.