<?php
/*
****************************************************************************
* class sql_data_show *
* Version 1.5 *
* *
* A PHP class for browsing through a large set of data *
* *
* Copyright (C) 2003 by Dragos Protung - hide@address.com *
* *
* This PHP class is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This PHP class is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* *
* Author: *
* Dragos Protung, 500164 Brasov, Romania, hide@address.com *
* *
****************************************************************************
*/
class sql_data_browsing {
/*
# @function sql_data_browsing() -- constructor
#
# @param $sql_result -- the result of the query
# @param $cur_page -- the curent page
# @param $records_per_page -- how many record are shown per page
# @param $cul_rows -- the colors for the rows (four colors) separated by "_" and with no "#" in front
# @param $no_data_text -- text to show if no data is retrived from the query
#
*/
function sql_data_browsing($sql_result, $cur_page, $records_per_page, $cul_rows, $no_data_text = "No data to show") {
$this -> sql_result = $sql_result;
$this -> cur_page = $cur_page;
$this -> records_per_page = $records_per_page;
$this -> cul_rows = $cul_rows;
$this -> no_data_text = $no_data_text;
$this -> sql_num_cols = @mysql_num_fields($this -> sql_result);
}
/*
#
# @function show_data() -- echos the data in a table
#
*/
function show_data() {
echo "
<script language=\"JavaScript\" src=\"table_color.js\"></script>
<table class=\"sql_data_browsing\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"100%\" id=\"sql_data_show\">
";
$nr_rand = 0;
if(@mysql_data_seek($this -> sql_result, ($this -> cur_page * $this -> records_per_page))) {
$this -> cul_rows = explode("_", $this -> cul_rows);
while ($db_cnt = mysql_fetch_row($this -> sql_result) and $nr_rand < $this -> records_per_page) {
$nr_rand++;
if (!($nr_rand % 2)) $culoare_rand = "#" . $this -> cul_rows[0];
else if ($nr_rand % 2) $culoare_rand = "#" . $this -> cul_rows[1];
echo "<tr class=\"sql_data_browsing\" onmouseover=\"setPointer(this, $nr_rand, 'over', '$culoare_rand', '" . "#" . $this -> cul_rows[2] . "', '" . "#" . $this -> cul_rows[3] . "');\" onmouseout=\"setPointer(this, $nr_rand, 'out', '$culoare_rand', '" . "#" . $this -> cul_rows[2] . "', '" . "#" . $this -> cul_rows[3] . "');\" onmousedown=\"setPointer(this, $nr_rand, 'click', '$culoare_rand', '" . "#" . $this -> cul_rows[2] . "', '" . "#" . $this -> cul_rows[3] . "');\">";
for ($i=0; $i<$this -> sql_num_cols; $i++) {
echo "<td class=\"sql_data_browsing\" bgcolor=\"$culoare_rand\" align=\"center\">" . $db_cnt[$i] . "</td>\n";
};
echo "</tr>\n";
}
}
else echo $this -> no_data_text;
echo "</table>\n";
}
}
?>