Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 11th, 2005, 09:40 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old November 11th, 2005, 11:40 AM
Authorized User
 
Join Date: Nov 2005
Location: Houston, TX, .
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to tonyrosen
Default

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.

  #3 (permalink)  
Old November 12th, 2005, 04:49 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset Empty Check Coby Access VBA 2 April 27th, 2007 04:09 PM
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
Recordset empty when opening querydef DeAnzaJig Access VBA 3 November 14th, 2005 09:31 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
Trap for empty recordset in a SP Mitch Access VBA 2 September 5th, 2003 04:47 PM





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