snrecords Posted November 17, 2008 Share Posted November 17, 2008 Hi all. I have a search page with a html form that passes several variables through. My results page retrieves the data using $_POST. My results page also uses the include statement to include my pagination code. The pagination code uses php functions which makes things easier BUT, I can't figure out why I can't retrieve my $_POST data and put it in one of the function of the pagination code. The pagination code is below: class PS_Pagination { var $php_self; var $rows_per_page; //Number of records to display per page var $total_rows; //Total number of rows returned by the query var $links_per_page; //Number of links to display per page var $sql; var $debug = false; var $conn; var $page; var $max_pages; var $offset; /** * Constructor * * @param resource $connection Mysql connection link * @param string $sql SQL query to paginate. Example : SELECT * FROM users * @param integer $rows_per_page Number of records to display per page. Defaults to 10 * @param integer $links_per_page Number of links to display per page. Defaults to 5 */ function PS_Pagination($connection, $sql, $rows_per_page = 10, $links_per_page = 5) { $this->conn = $connection; $this->sql = $sql; $this->rows_per_page = $rows_per_page; $this->links_per_page = $links_per_page; $this->php_self = htmlspecialchars($_SERVER['PHP_SELF']); if(isset($_GET['page'])) { $this->page = intval($_GET['page']); } } /** * Executes the SQL query and initializes internal variables * * @access public * @return resource */ function paginate() { if(!$this->conn) { if($this->debug) echo "MySQL connection missing<br />"; return false; } $all_rs = @mysql_query($this->sql); if(!$all_rs) { if($this->debug) echo "SQL query failed. Check your query.<br />"; return false; } $this->total_rows = mysql_num_rows($all_rs); @mysql_close($all_rs); $this->max_pages = ceil($this->total_rows/$this->rows_per_page); //Check the page value just in case someone is trying to input an aribitrary value if($this->page > $this->max_pages || $this->page <= 0) { $this->page = 1; } //Calculate Offset $this->offset = $this->rows_per_page * ($this->page-1); //Fetch the required result set $rs = @mysql_query($this->sql." LIMIT {$this->offset}, {$this->rows_per_page}"); if(!$rs) { if($this->debug) echo "Pagination query failed. Check your query.<br />"; return false; } return $rs; } /** * Display the link to the first page * * @access public * @param string $tag Text string to be displayed as the link. Defaults to 'First' * @return string */ function renderFirst($tag='First') { if($this->page == 1) { return $tag; } else { return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>'; } } When i put echo $_POST['myvariable']; outside of the functions it works, but when i put it inside it doesn't. I just want to make the link below include my $_POST['myvariable']. function renderFirst($tag='First') { if($this->page == 1) { return $tag; } else { return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>'; } Please help! Link to comment https://forums.phpfreaks.com/topic/133022-retrieve-variable/ Share on other sites More sharing options...
zenag Posted November 17, 2008 Share Posted November 17, 2008 $postvalues=$_POST['myvariable']; class PS_Pagination { var $postvalues; function urfunction{ echo $this->$postvalues; } Link to comment https://forums.phpfreaks.com/topic/133022-retrieve-variable/#findComment-691840 Share on other sites More sharing options...
snrecords Posted November 17, 2008 Author Share Posted November 17, 2008 Hi! I tried that and got this error Fatal error: Cannot access empty property any ideas? Link to comment https://forums.phpfreaks.com/topic/133022-retrieve-variable/#findComment-691846 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 <?php function renderFirst($tag='First', $your_variable) { // do whatever you want with $your_variable if($this->page == 1) { return $tag; } else { return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>'; } } ?> <?php $pagination = new PS_Pagination(); $your_variable = $pagination->renderFirst('First', $your_variable); ?> Link to comment https://forums.phpfreaks.com/topic/133022-retrieve-variable/#findComment-691849 Share on other sites More sharing options...
snrecords Posted November 17, 2008 Author Share Posted November 17, 2008 thank you! Link to comment https://forums.phpfreaks.com/topic/133022-retrieve-variable/#findComment-691868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.