Jump to content

if else is driving me INSANE!


dreamwest

Recommended Posts

I can tget this if else to work....and its driving me insane!

 

if (isset($_COOKIE['autoplay'])){
echo "";
}else{
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}
if  ($_COOKIE['autoplay'] === 'on'){ 
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}

Link to comment
Share on other sites

line 10.. (point 2 "PLAY")

	echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";

u should type

echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";

and the repair are

<?
if (isset($_COOKIE['autoplay']))
{
echo "";
}else{ //if (isset($_COOKIE['autoplay']))
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//else if (isset($_COOKIE['autoplay']))

if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){ //if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//elseif ($_COOKIE['autoplay'] === 'off')
?>

Link to comment
Share on other sites

Your logic makes no sense...

 

You first test if $_COOKIE['autoplay'] is set and if it is you echo nothing, then further down you ask if $_COOKIE['autoplay'] equals on or $_COOKIE['autoplay'] equals off echo some data. Wouldn't it be better to enclose those two if(s) on or off in the if ISSET $_COOKIE['autoplay']!

Link to comment
Share on other sites

line 10.. (point 2 "PLAY")

	echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";

u should type

echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";

and the repair are

<?
if (isset($_COOKIE['autoplay']))
{
echo "";
}else{ //if (isset($_COOKIE['autoplay']))
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//else if (isset($_COOKIE['autoplay']))

if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){ //if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//elseif ($_COOKIE['autoplay'] === 'off')
?>

 

WHOOHOO!! Works ....Thanks

 

Your logic makes no sense...

 

You first test if $_COOKIE['autoplay'] is set and if it is you echo nothing, then further down you ask if $_COOKIE['autoplay'] equals on or $_COOKIE['autoplay'] equals off echo some data. Wouldn't it be better to enclose those two if(s) on or off in the if ISSET $_COOKIE['autoplay']!

 

The first "if $_COOKIE['autoplay']" is for when theres no cookie, the rest of the script is for when they have a cookie either on or off.

 

But i can see your point..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.