Page 1 of 1
Empty Recordset Redirects
Posted: Sat Jan 14, 2006 8:30 am
by dgreenyc
I'm createing a simple application where there is a pop-upwindow that displays pictures of anyone that lives in a certain city. The result page displays all of the info of the person with a graphic on in the background. The querystring is based on the cityID. The problem that I have run into is when there are no persons living in that city. Instead of having the empty graphic page I would like to have the pop-upwindow redirected to another page which has a similar graphic but with no fields, only a message that says "Sorry - no one here." Is there a way to redirect the browser if the recordset is empty?
Thanks for any assistance.
-dg-
Posted: Sat Jan 14, 2006 8:36 am
by feyd
general idea:
Code: Select all
rows = database_row_count()
if rows = 0
header(); // redirection
else
do_page();
Posted: Sat Jan 14, 2006 8:45 am
by dgreenyc
Thanks for the quik response.
I'm not sure what I'm doing wrong with the header code - anytime that I have tried to use it I get a blank screen. Here's the code I had been working with.
Code: Select all
if ($rs_people is empty) {
header("picture_empty.php");
} else {
Posted: Sat Jan 14, 2006 8:59 am
by feyd
Posted: Sat Jan 14, 2006 9:59 am
by dgreenyc
Again - thanks for the quick (or quik) reply.
Not sure what I am doing wrong, but I am still getting a blank page. Here's the full recordset code -
Code: Select all
<?php require_once('Connections/worldfamily.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rs_people = 1;
$pageNum_rs_people = 0;
if (isset($_GET['pageNum_rs_people'])) {
$pageNum_rs_people = $_GET['pageNum_rs_people'];
}
$startRow_rs_people = $pageNum_rs_people * $maxRows_rs_people;
$colname_rs_people = "1";
if (isset($_GET['cityID'])) {
$colname_rs_people = (get_magic_quotes_gpc()) ? $_GET['cityID'] : addslashes($_GET['cityID']);
}
mysql_select_db($database_worldfamily, $worldfamily);
$query_rs_people = sprintf("SELECT * FROM people INNER JOIN cities ON people.cityID=cities.cityID INNER JOIN pictures ON people.picID=pictures.picID WHERE people.cityID = %s", $colname_rs_people);
$query_limit_rs_people = sprintf("%s LIMIT %d, %d", $query_rs_people, $startRow_rs_people, $maxRows_rs_people);
$rs_people = mysql_query($query_limit_rs_people, $worldfamily) or die(mysql_error());
$row_rs_people = mysql_fetch_assoc($rs_people);
if (isset($_GET['totalRows_rs_people'])) {
$totalRows_rs_people = $_GET['totalRows_rs_people'];
} else {
$all_rs_people = mysql_query($query_rs_people);
$totalRows_rs_people = mysql_num_rows($all_rs_people);
}
$totalPages_rs_people = ceil($totalRows_rs_people/$maxRows_rs_people)-1;
if ($rs_people is empty) {
header("Location: http://www.worldoffamily.com/picture_empty.php");
} else {
}
$queryString_rs_people = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rs_people") == false &&
stristr($param, "totalRows_rs_people") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rs_people = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rs_people = sprintf("&totalRows_rs_people=%d%s", $totalRows_rs_people, $queryString_rs_people);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
Do I need to have the redirect code in a seperate page from the picture detail page?
Posted: Sat Jan 14, 2006 10:58 am
by dgreenyc
Figured it out - thanks for your help.
-dg-