hi i want to direct my website to different pages
If there are competions that are active to show the page list of them else go to other page

i tried this but no luck

<?php
include_once "connect_to_mysql.php";

$extract = mysql_query("select * from tbl_competition WHERE fld_closed='N'");

while ($row = mysql_fetch_assoc($extract))

if ($rows <= 0) {          
header( 'Location: nocompetition.php' ) ;     
}      

if ($rows > 0) {          
 
header( 'Location: competition.php' ) ; 
}
Member Avatar for diafol

Several things:
no {} about while loop. Need a while anyway??
I assume you're after mysql_num_rows() and redirect on the strength of that.

I think you need something like this:

$extract = mysql_query("select * from tbl_competition WHERE fld_closed='N'");

if (mysql_num_rows($extract) > 0) {
    while ($row = mysql_fetch_assoc($extract)) {
        //Do your thing with the data
    }
} else { //No rows from MySQL
    //Put your redirect stuff here
}

And yeah, where are your {} and all the code for what you want to happen during the while() loop?

Try that:

<?php
include_once "connect_to_mysql.php";

$extract = mysql_query("select * from tbl_competition WHERE fld_closed='N'");
         
if(mysql_num_rows($extract) < 0){
header( 'Location: nocompetition.php' ) ;     
}
else{
header( 'Location: competition.php' ) ; 
}
?>

Hope that help.

thanks i tried the code and added "=" to the if line and its perfect! ..

Thank you

<?php
include_once "connect_to_mysql.php"; 

$extract = mysql_query("select * from tbl_competition WHERE fld_closed='N'"); 

if(mysql_num_rows($extract) <= 0){

header( 'Location: nocompetition.php' ) ;      

}else{

header( 'Location: competition.php' ) ;

}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.