dmschenk Posted September 12, 2007 Share Posted September 12, 2007 Hi Folks, I'm having a little coding problem using an if statement. I'm pretty sure that I'm using the syntax incorrectly but I can't seem to get it straightened out. Could someone please take a look at the code below and tell me where I went wrong? Basically this is a php page that builds a mock XML page for a flash player and the field "outlineAvail" has a decision to make. if "outlineAvail" is equal to 1 then echo **download the outline ........else echo nothing. If I wrap the if statement in single quotes it actually prints out the statement otherwise I can't get it to work at all. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<playlist>\n"; while($row_rsFCAG = mysql_fetch_assoc($rsFCAG)) { echo ("<sound " . " src=\"" . "/resources/sermons/audio/" . $row_rsFCAG["sermonURL"] . "\"" . " ol_avail=\"" . if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {echo "**download the outline";} else {echo "";} . "\"" . " stream=\"true\">" . $row_rsFCAG["seriesName"] . " " . $row_rsFCAG["sermonName"] . "</sound>\n"); } echo "</playlist>\n"; Thanks for your help Dave Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/ Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 Have you tried echoing out something besides a "" in the else? Then you will know if it is a problem with the compare statement or the if. Try this: $row_rsFCAG["outlineAvail"] with single quotes like this: $row_rsFCAG['outlineAvail']. I can't remember if double quotes will work in there. Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347199 Share on other sites More sharing options...
dmschenk Posted September 12, 2007 Author Share Posted September 12, 2007 The original statement used to be $row_rsFCAG["outlineAvail"] and it worked fine but I'm trying to tweak the code so that the user only has to hit a checkbox when entering info into the database. The checkbox adds a 1 or 0 to the DB and this code makes a decision based on the output of the DB whether to echo some text or not....except it has an error! Also note that all by itself the code works fine and I tried to scavenge it from some code that converted 1/0 to Yes/No as seen below: <?php if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {echo "Yes";} else {echo "No";} ?> its when I add it to the other code that it stops working Thanks Dave Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347235 Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 Does it print and of the echo ("<sound " . ".... statement? I don't see anything wrong with the if part. What I would do is to echo out all of the $row variables that you have and make sure that what you expect to be in them is actually in them. Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347242 Share on other sites More sharing options...
dmschenk Posted September 12, 2007 Author Share Posted September 12, 2007 This is a link to the original output: http://www.freedomchristian.org/audio_sermons/fsArchived.php As you can see the ol_avail field equals either 0 or 1 in all cases and like you, I didn't see anything wrong in the "if" statement either but I still can't get it to work tis only a matter of time ..... it'll get worked out Thanks Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347262 Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 is that code in your first post the entire block? I don't see where it prints out things like author= and outline= into that tag. Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347266 Share on other sites More sharing options...
dmschenk Posted September 12, 2007 Author Share Posted September 12, 2007 no it wasn't ... for the sake of making it easier to read I took some of the code out But here is the rest of the code: mysql_select_db($fcag_db_Master, $db_fcag_admin); $query_rsFCAG = "SELECT fcag_sermons.*, fcag_speaker.speakerName FROM fcag_sermons, fcag_speaker WHERE fcag_sermons.online = 1 AND fcag_sermons.archived = 0 AND fcag_sermons.speakersID = fcag_speaker.speakersID ORDER BY fcag_sermons.dateAdded DESC"; $rsFCAG = mysql_query($query_rsFCAG, $db_fcag_admin) or die(mysql_error()); #$row_rsFCAG = mysql_fetch_assoc($rsFCAG); #$totalRows_rsFCAG = mysql_num_rows($rsFCAG); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<playlist>\n"; while($row_rsFCAG = mysql_fetch_assoc($rsFCAG)) { echo ("<sound " . " src=\"" . "/resources/sermons/audio/" . $row_rsFCAG["sermonURL"] . "\"" . " author=\"" . $row_rsFCAG["speakerName"] . "\"" . " outline=\"" . "/resources/sermons/outlines/" . $row_rsFCAG["outlineURL"] . "\"" . " ol_avail=\"" . $row_rsFCAG["outlineAvail"] . "\"" . " stream=\"true\">" . $row_rsFCAG["seriesName"] . " " . $row_rsFCAG["sermonName"] . "</sound>\n"); } echo "</playlist>\n"; mysql_free_result($rsFCAG); ?> Plus the expoited line <?php if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {echo "**download the outline";} else {echo "";} ?> And the Modified version: mysql_select_db($fcag_db_Master, $db_fcag_admin); $query_rsFCAG = "SELECT fcag_sermons.*, fcag_speaker.speakerName FROM fcag_sermons, fcag_speaker WHERE fcag_sermons.online = 1 AND fcag_sermons.archived = 0 AND fcag_sermons.speakersID = fcag_speaker.speakersID ORDER BY fcag_sermons.dateAdded DESC"; $rsFCAG = mysql_query($query_rsFCAG, $db_fcag_admin) or die(mysql_error()); #$row_rsFCAG = mysql_fetch_assoc($rsFCAG); #$totalRows_rsFCAG = mysql_num_rows($rsFCAG); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<playlist>\n"; while($row_rsFCAG = mysql_fetch_assoc($rsFCAG)) { echo ("<sound " . " src=\"" . "/resources/sermons/audio/" . $row_rsFCAG["sermonURL"] . "\"" . " author=\"" . $row_rsFCAG["speakerName"] . "\"" . " outline=\"" . "/resources/sermons/outlines/" . $row_rsFCAG["outlineURL"] . "\"" . " ol_avail=\"" . 'if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {echo "**download the outline";} else {echo "";}' . "\"" . " stream=\"true\">" . $row_rsFCAG["seriesName"] . " " . $row_rsFCAG["sermonName"] . "</sound>\n"); } echo "</playlist>\n"; mysql_free_result($rsFCAG); ?> Dave Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347274 Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 So, instead of printing the 0 or 1 you want to print "**download the outline" or ""? If yes, what does it print when you run it with the if statement? Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347278 Share on other sites More sharing options...
dmschenk Posted September 13, 2007 Author Share Posted September 13, 2007 That's correct .. instead of 1 or 0 I want to print out the message When I run the if statement, the statement itself is being printed out as if it were a literal statement Example output: <?xml version="1.0" encoding="UTF-8" ?> <playlist> <sound src="/resources/sermons/audio/MothersDay.mp3" author="Karen Strong" outline="/resources/sermons/outlines/" ol_avail="if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {echo "**download the outline";} else {echo "";} " stream="true">Mothers Day</sound> <playlist> Dave Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-347791 Share on other sites More sharing options...
dmschenk Posted September 14, 2007 Author Share Posted September 14, 2007 The solution was to create an alias above the echo statement that changed the 1/0 to the desired string. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<playlist>\n"; while($row_rsFCAG = mysql_fetch_assoc($rsFCAG)) { if (!(strcmp($row_rsFCAG["outlineAvail"],1))) {$outlineAvail = "**download the outline";} else {$outlineAvail = "";} echo ("<sound " . " src=\"" . "/resources/sermons/audio/" . $row_rsFCAG["sermonURL"] . "\"" . " author=\"" . $row_rsFCAG["speakerName"] . "\"" . " outline=\"" . "/resources/sermons/outlines/" . $row_rsFCAG["outlineURL"] . "\"" . " ol_avail=\"" . $outlineAvail . "\"" . " stream=\"true\">" . $row_rsFCAG["seriesName"] . " " . $row_rsFCAG["sermonName"] . "</sound>\n"); } echo "</playlist>\n"; Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/#findComment-348112 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.