Here is the php file that calls to the class. It doesn't seem to have anything that is global, but as I said before, I am not very familiar with this.
<?
mysql_connect("localhost","username","password"); mysql_select_db("MyDatabase"); // this is a dump variable just for demonstration purposes $cod= 5;
// how many rows do you want per page??? $step = 10;
# Include class file include ("pn.class.php");
# the sql query without Limit
$sql = "select asset_id, developer, title, version, platform from software_assets ORDER BY asset_id";
$res= mysql_query( $sql );
$total = mysql_num_rows( $res );
# initiate class # parameters explanation # 1st param : the sql query without Limit expretion # 2nd param : number of elements to display per page. # 3rd param : current page; this should be null # 4rth param : total rows of query //$buttons = new pn_buttons( $sql, $step, $page ); $buttons = new pn_buttons( $sql, $step, $page, $total );
# $buttons->limited_query is the sql query with limit expretion # class create this $res = mysql_query ($buttons->limited_query);
echo " <html> <body>";
// table headers describing columns
echo "
<table width=\"500\" border=\"1\" cellspacing=\"5\" cellpadding=\"3\">
<tr bgcolor=\"#bbbbbb\">
<td align=\"center\"><b>Asset ID</b></td>
<td align=\"center\"><b>Developer</b></td>
<td align=\"center\"><b>Software Title</b></td>
<td align=\"center\"><b>Version</b></td>
<td align=\"center\"><b>Platform</b></td>
</tr>
";
// list elements one by one until there are no more in the database
while ( list ( $asset_id, $developer, $title, $version, $platform ) = mysql_fetch_row($res) ){
echo "
<tr>
<td align=\"left\"><a href=\"editsoftwareasset.php?id=$asset_id\">$asset_id</a></td>
</td>
<td align=\"left\">$developer
</td>
<td align=\"left\">$title
</td>
<td align=\"left\">$version
</td>
<td align=\"left\">$platform
</td>
</tr>
";
}
// close table once list elements loop is finished echo "</table>";
// Beginning of prev/next buttons. Will be centered in the table. echo" <table width=\"500\" border=\"1\"> <tr align=\"center\"> <td> <center>";
# Create Prev and next buttons
# parameters explanation
# 1st param : the page that displays results with ? at the end
# 2nd param : additional url parameters e.g. cid=$cid&top=$top
# 3rd param : Text to display in next link
# 4th param : Text to display in previous link
$buttons->make_buttons("pn_classexample.php?","cid=$cod","Next Results", "Previous Results");
# display previous and next links
echo $buttons->previous_button . " " .$buttons->next_button;
# display current page number and total pages number
echo "<br>Page ". $buttons->current_page . " of ". $buttons->query_total_pages;
echo "<br><br><br>";
echo $buttons->count_all_pages("pn_classexample.php?","cid=$cid");
?> </center> </td> </tr> </table> </body> </html>
On Tuesday, March 18, 2003, at 11:02 AM, CPT John W. Holmes wrote:
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...
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php