Code no longer works in PHP5

My web host recently updated the version of PHP that runs on their servers to version 5.3. When they did this, the code that has been running on my website for years no longer works. I think most of the problem is in this routine that displays the results of a MySQL query in pages and has navigation links at the bottom. I didn’t write this myself, but found it on the web. When I first setup my website years ago, I just learned enough PHP to accomplish what I needed, and haven’t used it since, so I’m not having much luck finding the problem here. I would really appreciate any help, thanks! navbar code is below. If this looks OK, maybe the problem is in another bit of code, I can post more.

[php]<?php
/*
Class navbar
Copyright Joao Prado Maia ([email protected])

Sweet little class to build dynamic navigation links. Please
notice the beautiful simplicity of the code. This code is
free in any way you can imagine. If you use it on your own
script, please leave the credits as it is. Also, send me an
e-mail if you do, it makes me happy :slight_smile:

Below goes an example of how to use this class:

<?php $nav = new navbar; $nav->numrowsperpage = 3; $sql = "SELECT * FROM links "; $result = $nav->execute($sql, $db, "mysql"); $rows = mysql_num_rows($result); for ($y = 0; $y < $rows; $y++) { $data = mysql_fetch_object($result); echo $data->url . "
\n"; } echo "
\n"; $links = $nav->getlinks("all", "on"); for ($y = 0; $y < count($links); $y++) { echo $links[$y] . "  "; } ?>

*/

class navbar {
// Default values for the navigation link bar
var $numrowsperpage = 10;
var $str_previous = “Previous page”;
var $str_next = “Next page”;
// Variables used internally
var $file;
var $total_records;

// The next function runs the needed queries.
// It needs to run the first time to get the total
// number of rows returned, and the second one to
// get the limited number of rows.
//
// $sql parameter :
// . the actual SQL query to be performed
//
// $db parameter :
// . the database connection link
//
// $type parameter :
// . “mysql” - uses mysql php functions
// . “pgsql” - uses pgsql php functions
function execute($sql, $db, $type = “mysql”) {
global $total_records, $row, $numtoshow;

$numtoshow = $this->numrowsperpage;
if (!isset($row)) $row = 0;
$start = $row * $numtoshow;
if ($type == "mysql") {
  $result = mysql_query($sql, $db);
  $total_records = mysql_num_rows($result);
  $sql .= " LIMIT $start, $numtoshow";
  $result = mysql_query($sql, $db);
} elseif ($type == "pgsql") {
  $result = pg_Exec($db, $sql);
  $total_records = pg_NumRows($result);
  $sql .= " LIMIT $numtoshow, $start";
  $result = pg_Exec($db, $sql);
}
return $result;

}

// This function creates a string that is going to be
// added to the url string for the navigation links.
// This is specially important to have dynamic links,
// so if you want to add extra options to the queries,
// the class is going to add it to the navigation links
// dynamically.
function build_geturl()
{
global $REQUEST_URI, $REQUEST_METHOD, $_GET, $_POST;

list($fullfile, $voided) = explode("?", $REQUEST_URI);
$this->file = $fullfile;
$cgi = $REQUEST_METHOD == 'GET' ? $_GET : $_POST;
reset ($cgi);
while (list($key, $value) = each($cgi)) {
  if ($key != "row")
    $query_string .= "&" . $key . "=" . $value;
}
return $query_string;

}

// This function creates an array of all the links for the
// navigation bar. This is useful since it is completely
// independent from the layout or design of the page.
// The function returns the array of navigation links to the
// caller php script, so it can build the layout with the
// navigation links content available.
//
// $option parameter (default to “all”) :
// . “all” - return every navigation link
// . “pages” - return only the page numbering links
// . “sides” - return only the ‘Next’ and / or ‘Previous’ links
//
// $show_blank parameter (default to “off”) :
// . “off” - don’t show the “Next” or “Previous” when it is not needed
// . “on” - show the “Next” or “Previous” strings as plain text when it is not needed
function getlinks($option = “all”, $show_blank = “off”) {
global $total_records, $row, $numtoshow;

$extra_vars = $this->build_geturl();
$file = $this->file;
$number_of_pages = ceil($total_records / $numtoshow);
$subscript = 0;
for ($current = 0; $current < $number_of_pages; $current++) {
  if ((($option == "all") || ($option == "sides")) && ($current == 0)) {
    if ($row != 0)
      $array[0] = '<A HREF="' . $file . '?row=' . ($row - 1) . $extra_vars . '">' . $this->str_previous . '</A>';
    elseif (($row == 0) && ($show_blank == "on"))
      $array[0] = $this->str_previous;
  }

  if (($option == "all") || ($option == "pages")) {
    if ($row == $current)
      $array[++$subscript] = ($current > 0 ? ($current + 1) : 1);
    else
      $array[++$subscript] = '<A HREF="' . $file . '?row=' . $current . $extra_vars . '">' . ($current + 1) . '</A>';
  }

  if ((($option == "all") || ($option == "sides")) && ($current == ($number_of_pages - 1))) {
    if ($row != ($number_of_pages - 1))
      $array[++$subscript] = '<A HREF="' . $file . '?row=' . ($row + 1) . $extra_vars . '">' . $this->str_next . '</A>';
    elseif (($row == ($number_of_pages - 1)) && ($show_blank == "on"))
      $array[++$subscript] = $this->str_next;
  }
}
return $array;

}
}
?>
[/php]

Here’s some additional code that calls the code above, maybe the problem is here. The code below displays the data in my database in pages (or, at least it used to), with navigation links at the bottom. But now, the first page displays, but clicking on any of the navigation links does not navigate thru the table, the same records appear.

[code]<?php
// database connection stuff
$db = mysql_connect(“localhost”, “******”, “******”);
mysql_select_db(“dgunning”, $db) or die(mysql_errno() . ": " . mysql_error() . “
”);

// including the navbar class
include("./navbar.php");
// initiate it!
$nav = new navbar;
// set how many records to show at a time
$nav->numrowsperpage = 27;
$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url FROM op, arch WHERE op.archno = arch.archno ";

if ($Select1==‘Address’) {
$sql .= “ORDER BY op.street, op.direction, LPAD(op.stnum,6,‘0’) ASC”;}
elseif ($Select1==‘Architect’) {
$sql .= “ORDER BY arch.architect, op.street, op.direction, LPAD(op.stnum,6,‘0’) ASC”;}
else {$sql .= “ORDER BY op.yearbuilt, op.street, op.direction, LPAD(op.stnum,6,‘0’) ASC”;}

// the third parameter of execute() is optional
$result = $nav->execute($sql, $db, “mysql”);
// handle the returned result set
$rows = mysql_num_rows($result);
echo “Return to databases search page
“;
print (”

\n”);
print ("
Original Owner");
print ("
#");
print ("
“);
print (”
Street");
print ("
Architect");
print ("
Year Built");
print ("
Details");
for ($y = 0; $y < $rows; $y++) {
$data = mysql_fetch_row($result);

//while ($row = mysql_fetch_row ($result))
//{
//print ("<TR bgcolor=“ivory”>\n");

       if($y % 2) { //this means if there is a remainder
	echo ("<TR bgcolor=\"LemonChiffon\">\n");
	
                  } else { //if there isn't a remainder we will do the else
	echo ("<TR bgcolor=\"honeydew\">\n");}


for ($i = 0; $i < (mysql_num_fields ($result))-1; $i++) {                 
	printf ("<TD ><font color='blaCK' face='verdana' size='1'>%s</TD>\n", htmlspecialchars ($data[$i]));
}
$fstreet=str_replace(' ','+',$data[3]);
PRINT ("<TD><A HREF=byadd.php?stnum=$data[1]&dir=$data[2]&street=$fstreet>Link</A></TD>");
PRINT ("</TR>\n");

}
print ("

\n");

echo “


\n”;
// build the returned array of navigation links
$links = $nav->getlinks(“all”, “on”);
print "\n";
for ($y = 0; $y < count($links); $y++) {
echo $links[$y] . "  ";
}
print “
\n”;
?>
[/code]
Sponsor our Newsletter | Privacy Policy | Terms of Service