Re: Register_globals question

From: Date: Tue, 18 Mar 2003 17:02:29 +0000
Subject: Re: Register_globals question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140141@lists.php.net to get a copy of this message
> I found a class that allows you to have a multiple page listing, where > it displays a certain number of items, and then you click on the next > page to show the next results. I found that it needs to have > register_globals turned on. I am learning, and would like to have > someone look at the class to tell me where in this class > register_globals is required. I have emailed the person that created > the class, I am just trying to understand this. > > Mike > > Here is the class code: > > <? > > class pn_buttons{ > > /* Public Variables */ > var $query_total_pages = 0; > var $limited_query; > var $next_button; > var $previous_button; > > /* Functions */ > function pn_buttons($sql, $step, $page=0){ > $result = mysql_query( $sql ); > $query_total_rows = mysql_num_rows( $result ); > > // if query return some rows > if ( $query_total_rows>0 ){ > > if ( $query_total_rows%$step!=0 ){ > $total_pages = intval( $query_total_rows/$step)+1; > }else{ > $total_pages = $query_total_rows/$step ; > } > > $this->query_total_pages = $total_pages; > > // if page is set > if ( empty($page) ) { > $from = 0; > $this->current_page= 1; > }else{ > if ( $page <= $this->query_total_pages ) { > $from = $step * ( $page - 1 ); > $this->current_page= $page; > }else{ > $from = 0; > $this->current_page= 1; > } > } > > $this->limited_query = $sql . " LIMIT ". $from .", ". > $step; > } > > } // end function > > // create previous and next buttons > function make_buttons( $link, $link_params, $txt_next="next", > $txt_previous="previous", $image="" ){ > > if ( $this->query_total_pages>1 ){ > > if ( ($this->current_page < $this->query_total_pages) && > ($this->current_page>1) ){ > $next_page = $this->current_page+1; > $prev_page = $this->current_page-1; > $next_lnk = "<a href='".$link . $link_params . > "&page=". $next_page ."'>$txt_next</a>"; > $prev_lnk = "<a href='".$link . $link_params . > "&page=". $prev_page ."'>$txt_previous</a>"; > }else if( ($this->current_page < > $this->query_total_pages) && ($this->current_page==1) ){ > $next_page = $this->current_page+1; > $prev_page = ""; > $next_lnk = "<a href='".$link . $link_params . > "&page=". $next_page ."'>$txt_next</a>"; > $prev_lnk = ""; > }else if( $this->current_page >= $this->query_total_pages > ){ > $next_page = ""; > $prev_page = $this->current_page-1; > $next_lnk = ""; > $prev_lnk = "<a href='".$link . $link_params . > "&page=". $prev_page ."'>$txt_previous</a>"; > } > $this->next_button = $next_lnk; > $this->previous_button = $prev_lnk; > } > > } // end function > > // display all pages > function count_all_pages( $link, $link_params ){ > for ($i=1; $i<=$this->query_total_pages; $i++){ > if ($i==$this->current_page){ > echo "<b>[$i]</b>"; > }else{ > echo "<a > href='$link$link_params&page=$i'>[$i]</a>"; > } > } > } > > } // end Class Since it's a class, register_global variables would not have any scope within it. Since there are no 'global' calls in any of the methods, it doesn't look like it's relying on any outside variables. Everything this script acts upon is passed to it, so it does not rely on register globals. How this class was implemented may rely on them, though. ---John Holmes...

« previous php.general (#140141) next »