shreef_1990 Posted April 12, 2012 Share Posted April 12, 2012 need help in if statement i will use it wordpress i am semi brand new in php and html i forged it with the help of c and c ++ visual basic LOL and some tutorial but did not work if any one can help making it work <?php $Shreef = <?php echo "get_post_meta($post->ID, 'sub', true);" ?> if ($Shreef=="Subbed"){ <font color="green"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> } else { if ($Shreef=="Raw") <font color="red"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> else { <?php echo "get_post_meta($post->ID, 'sub', true);" ?>} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/ Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 need help in if statement i will use it wordpress i am semi brand new in php and html i forged it with the help of c and c ++ visual basic LOL and some tutorial but did not work if any one can help making it work <?php if(isset($_POST['sub'])){ $Shreef = $post->ID, 'sub', true);" ?> if ($Shreef=="Subbed"){ <font color="green"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> } else { if ($Shreef=="Raw") <font color="red"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> else { <?php echo "get_post_meta($post->ID, 'sub', true);" ?>} } ?> <?php marks the start of the php code. ?> marks the end of the php code. Don't start it again before you have ended it. Turn on error reporting, so you get some idea about what is wrong and what it expects. $_POST[] is the variable/array for post data, but I'm not sure if that's what you are trying to do, neither have I worked with wordpress. EDIT: You never ended the CODE tag, so the code tag was added on the end of my post... Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/#findComment-1336732 Share on other sites More sharing options...
shreef_1990 Posted April 12, 2012 Author Share Posted April 12, 2012 it did not work look forget it was wordpress <?php echo "get_post_meta($post->ID, 'sub', true);" ?> == return string value i stored in shreef i want to color this string value so i used if if string value was subbed print green "subbed " from the answer of if and have two other answer so i used two other else but it did not complete first start <?php did not read final ?> and so i needed to know if there are some special character i had to escape and how <?php $Shreef = <?php echo "get_post_meta($post->ID, 'sub', true);" ?> if ($Shreef=="Subbed"){ <font color="green"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> } else { if ($Shreef=="Raw") <font color="red"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> else { <?php echo "get_post_meta($post->ID, 'sub', true);" ?>} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/#findComment-1336738 Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 it did not work look forget it was wordpress <?php echo "get_post_meta($post->ID, 'sub', true);" ?> == return string value i stored in shreef i want to color this string value so i used if if string value was subbed print green "subbed " from the answer of if and have two other answer so i used two other else but it did not complete first start <?php did not read final ?> and so i needed to know if there are some special character i had to escape and how <?php $Shreef = <?php echo "get_post_meta($post->ID, 'sub', true);" ?> if ($Shreef=="Subbed"){ <font color="green"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> } else { if ($Shreef=="Raw") <font color="red"> <?php echo "get_post_meta($post->ID, 'sub', true);" ?> </font> else { <?php echo "get_post_meta($post->ID, 'sub', true);" ?>} } ?> You still seem to start PHP again after having started it without ending it first..... Just in the two first lines of the code you start PHP twice and not before the end of the line you end it. This as far as I know is wrong. <?php $Shreef = get_post_meta($post->ID, 'sub', true); if($Shreef=='Subbed'){ echo '<font color="green">'.$Shreef.'</font>'; }elseif($Shreef=='Raw'){ echo '<font color="red">'.$Shreef.'</font>'; }else{ echo $Shreef; } ?> ^ Proper code. Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/#findComment-1336746 Share on other sites More sharing options...
shreef_1990 Posted April 12, 2012 Author Share Posted April 12, 2012 as i do not know i did not know about You still seem to start PHP again after having started it without ending it first..... Just in the two first lines of the code you start PHP twice and not before the end of the line you end it. This as far as I know is wrong. as for what i know Your editing is working really good Working Thanks my friend Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/#findComment-1336752 Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 as i do not know i did not know about You still seem to start PHP again after having started it without ending it first..... Just in the two first lines of the code you start PHP twice and not before the end of the line you end it. This as far as I know is wrong. as for what i know Your editing is working really good Working Thanks my friend I can't edit the post that long after I posted it. I edited the post mainly because it first wasn't possible to see due to an code tag at the end of my post. It somehow got connected with your post. That I had to edit, and I think I fixed a typo or two. Quote Link to comment https://forums.phpfreaks.com/topic/260812-need-help-in-if-statement/#findComment-1336754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.