";
$result = mysql_query($query) or die("SQL query failed: '$query' - ".mysql_error());
$total_num_rows = mysql_num_rows($result);
mysql_free_result($result);
}
$url .= "&total_num_rows=$total_num_rows";
if (isset($GLOBALS["limit_start"])) {
$limit_start = $GLOBALS["limit_start"];
if (isset($GLOBALS["limit_length"])) {
$limit_length=$GLOBALS["limit_length"];
} else {
$limit_length="";
}
if ($limit_start!=-1) {
$query .= " limit $limit_start";
if ($limit_length) {
$query .= ",$limit_length";
}
}
} else {
$limit_length = $limit_start = "";
}
# escape URL
$url = ereg_replace("[ ]","+",$url);
global $debug;
if (isset($debug)) {
echo "URL: $url
\n";
echo "Query: $query
\n";
}
$result = mysql_query($query) or die("SQL query failed");
if (!$result) {
echo "Unable to perform query.\n";
return 0;
}
$num_rows = mysql_num_rows($result);
if ($num_rows==0) {
return 0;
}
$field_count = mysql_num_fields($result);
echo "$num_rows entries";
if ($total_num_rows>$num_rows) {
echo " (out of $total_num_rows total)";
}
echo ":
\n";
echo "
\n";
# print table header
global $conversion_table,$dont_display,$centering,$default_alignment,$coloring,$header_coloring,$dont_link;
global $default_color,$default_header_color,$row_coloring_function;
global $pass_on;
$i=0;
while ($field=mysql_fetch_field($result)) {
$fieldnames[$i] = $field->name;
$tablenames[$i] = $field->table;
if (strlen($tablenames[$i])>0 && substr($tablenames[$i],0,3)!="SQL") {
$fullnames[$i] = $tablenames[$i].".".$fieldnames[$i];
} else {
$fullnames[$i] = $fieldnames[$i];
}
if (isset($conversion_table[$fullnames[$i]])) {
$display_fieldname = $conversion_table[$fullnames[$i]];
} else if (isset($conversion_table[$fieldnames[$i]])) {
$display_fieldname = $conversion_table[$fieldnames[$i]];
} else {
$display_fieldname=$fieldnames[$i];
}
if (isset($header_coloring[$fullnames[$i]])) {
$add_attributes = "bgcolor=\"#".$header_coloring[$fullnames[$i]]."\"";
} else if (isset($header_coloring[$fieldnames[$i]])) {
$add_attributes = "bgcolor=\"#".$header_coloring[$fieldnames[$i]]."\"";
} else if (isset($coloring[$fullnames[$i]])) {
$add_attributes = "bgcolor=\"#".$coloring[$fullnames[$i]]."\"";
} else if (isset($coloring[$fieldnames[$i]])) {
$add_attributes = "bgcolor=\"#".$coloring[$fieldnames[$i]]."\"";
} else if (isset($default_header_color)) {
$add_attributes = "bgcolor=\"#".$default_header_color."\"";
} else if (isset($default_color)) {
$add_attributes = "bgcolor=\"#".$default_color."\"";
} else {
$add_attributes="";
}
if (!isset($dont_display[$fullnames[$i]]) && !isset($dont_display[$fieldnames[$i]])) {
if (isset($dont_link[$fullnames[$i]]) || isset($dont_link[$fieldnames[$i]])) {
$link=0;
} else {
$link=1;
}
echo "| ";
if ($link) {
echo "";
}
$df = ereg_replace("<", "<", $display_fieldname);
$df = ereg_replace(">", ">", $df);
echo $df;
if ($link) {
echo "";
}
echo " | ";
}
$i++;
}
echo "
\n";
# print table data
global $external_processing_function;
while ($row=mysql_fetch_array($result)) {
if (isset($row_coloring_function)) {
print "";
} else {
echo "
\n";
}
for ($i=0; $i<$field_count; $i++) {
if (strlen($row[$i])==0) {
$row[$i]= " ";
}
if (!isset($dont_display[$fullnames[$i]]) && !isset($dont_display[$fieldnames[$i]])) {
if (isset($centering[$fullnames[$i]])) {
$align = $centering[$fullnames[$i]];
} else if (isset($centering[$fieldnames[$i]])) {
$align = $centering[$fieldnames[$i]];
} else if (isset($default_alignment)) {
$align = $default_alignment;
} else {
$align = "left";
}
if (isset($coloring[$fullnames[$i]])) {
$add_attributes = "bgcolor=\"#".$coloring[$fullnames[$i]]."\"";
} else if (isset($coloring[$fieldnames[$i]])) {
$add_attributes = "bgcolor=\"#".$coloring[$fieldnames[$i]]."\"";
} else if (isset($default_color)) {
$add_attributes = "bgcolor=\"#".$default_color."\"";
} else {
$add_attributes="";
}
echo "| ";
if (isset($external_processing_function)) {
$external_processing_function($fieldnames[$i],$tablenames[$i],$row[$i],&$row);
} else {
$df = ereg_replace("<", "<", $row[$i]);
$df = ereg_replace(">", ">", $df);
echo "$df\n";
}
echo " | ";
}
}
}
echo "
\n";
if ($num_rows!=$total_num_rows) {
if ($limit_length && $limit_start!=-1) {
echo "
\n";
}
mysql_free_result($result);
}
return $num_rows;
}
?>