0

Ok here is the code. `

mysql_query("UPDATE `special` SET `Counter` = `Counter` - 1");
$Counter = mysql_query("SELECT Counter FROM special where Id = 1");
if($Counter == 0)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=winner.php\">";

mysql_query("UPDATE `special` SET `Counter` = `Counter` + 500");
}

else

{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}

?>

im attempting to create a counter that starts at 500 and every visit it counts down by 1 till it hits 0 when it does it should go to the winner.php page and reset the counter to 500.

What is happening is it hits zero and never goes to winner.php or resets the counter. where am I messing up? It goes to the index page just fine. although i guess i have extra code to go to the index page. this coding will be called from the index so can i have a else do nothing? such as else {}.

4
Contributors
8
Replies
10
Views
5 Years
Discussion Span
Last Post by Zagga
0

is happening is it hits zero and never goes to winner.ph

It is not going to winner.php because mysql_query will not gives you the resultset and not the count. If you need count then do as following

$resultSet = mysql_query("YOUR QUERY COMES HERE");
$counter = mysql_num_rows($resultSet); // Now your counter variable will have value
if($counter == 0)
.
..
....
0

$counter = mysql_num_rows($resultSet);

well now it goes to winner.php and resets the counter, however it keeps going to the winner page...

0

here is what i have now....

mysql_query("UPDATE `special` SET `Counter` = `Counter` - 1");
$resultSet = mysql_query("SELECT Counter FROM special where Id = 1");
$Counter = mysql_num_rows($resultSet);
if($Counter == 0)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=winner.php\">";

mysql_query("UPDATE `special` SET `Counter` = `Counter` + 500");
}

else

{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}

?>

and now again it hits zero and does not go to the winner page or update the counter. So its not reading the ounter value again.

0

Hi azgold,

try:

$counterValue = mysql_query("SELECT Counter FROM special where Id = '1'");
$newCounterValue = $counterValue -1;

if ($counterValue == 0){
    mysql_query("UPDATE special SET Counter='500'");
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=winner.php\">";
} else {
    mysql_query("UPDATE special SET Counter='$newCounterValue'");
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
?>

In your original post you asked if you could have an empty ELSE statement. The ELSE clause is optional, so yes you can leave it out if you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.