Subject: Empty recordset = redirect
Posted By: frankriedel Post Date: 11/11/2005 8:40:42 AM
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

Reply By: tonyrosen Reply Date: 11/11/2005 10:40:22 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.

Reply By: frankriedel Reply Date: 11/12/2005 3:49:01 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


Go to topic 36495

Return to index page 437
Return to index page 436
Return to index page 435
Return to index page 434
Return to index page 433
Return to index page 432
Return to index page 431
Return to index page 430
Return to index page 429
Return to index page 428