Jump to content

[SOLVED] if statement help


dmschenk

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/69074-solved-if-statement-help/
Share on other sites

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.

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

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

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  ;D

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.