p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP How-To (http://p2p.wrox.com/forumdisplay.php?f=98)
-   -   Empty recordset = redirect (http://p2p.wrox.com/showthread.php?t=35044)

frankriedel November 11th, 2005 09:40 AM

Empty recordset = redirect
 
Is it possible to make a PHP code that redirect to another page if a recordset is EMPTY ??

If so - give an example please ;o)

Regards
Frank


tonyrosen November 11th, 2005 11:40 AM

sure it is ...

<?
// make your database connection
// grab recordset
// check to see if the recordset is empy
if ($your_record_set is empty) {
    header("Location: /page.php");
} else {
    // work with the record set.
}
?>

The catch is that this has to be at the top of the page before browser headers are sent. Top lines, no whitespace above it and no HTML above it.


frankriedel November 12th, 2005 04:49 AM

Thansk sir !
But i only get a blank page it do not redirect...

here is the code:

<?php
session_start();
$_SESSION['aktuel_uge'] = date("W")+1;
$_SESSION['uge'] = date("W");
?>
<?php
include("adminpro_class.php");
$prot=new protect();
if ($prot->showPage)
$curUser=$prot->getUser();
$_SESSION['user'] = date("W").$curUser ;
$curUser=$prot->getUser();
$_SESSION['userN'] = (date("W")+1).$curUser ;
$curUserV=$prot->getUserV();
$_SESSION['buy_v_user'] = $curUserV ;
{
?>
<?php require_once('Connections/DBZ.php');?>
<?php
// make your database connection
// grab recordset
$colname_Recordset2 = "1";
if (isset($HTTP_SESSION_VARS['userN'])) {
$colname_Recordset2 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['userN'] : addslashes($HTTP_SESSION_VARS['userN']);
}
mysql_select_db($database_DBZ, $DBZ);
$query_Recordset2 = sprintf("SELECT * FROM userbuy WHERE uge = '%s'", $colname_Recordset2);
$Recordset2 = mysql_query($query_Recordset2, $DBZ) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
// check to see if the recordset is empy
if ($Recordset2 is empty) {
    header("Location: /bestillingsside1a.php");
} else {
    // work with the record set. - here come the rest of the pagecode


All times are GMT -4. The time now is 10:40 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.