Jetmatt777 Posted March 21, 2008 Share Posted March 21, 2008 What I'm trying to do is pull out 1 piece of data from my db that will go into an if statement, and a different code will go out on one variable being true or false, or if the data does not exist. I hope that makes sense. <?php$con = mysql_connect("localhost","******","*****");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("**********",$con);$book= $_GET['book'];$chapter= $_GET['chapter'];$verse= $_GET['verse'];$result = mysql_query("SELECT * FROM bible WHERE book='$book' AND chapter='$chapter' AND verse='$verse'");while($row = mysql_fetch_array($result));$d= $row['des']; if ($d = "beg") { echo "Beginning"; } if ($d = "end") { echo "End"; } mysql_close($con);?> When I run the code, both echoes appear like this: BeginningEnd when only one or neither should appear.I hope that made a little sense of what I'm trying to accomplish.Some of the code might not appear correctly in sequence because when I copied the code over, it left out the line breaks.ThanksMatt Link to comment Share on other sites More sharing options...
Synook Posted March 22, 2008 Share Posted March 22, 2008 You are using the assignment operator (=), you have to use == if ($d == "beg") { echo "Beginning"; } if ($d == "end") { echo "End"; } Link to comment Share on other sites More sharing options...
Jetmatt777 Posted March 22, 2008 Author Share Posted March 22, 2008 Thanks, I tried that, now I just get a blank page. Link to comment Share on other sites More sharing options...
Synook Posted March 22, 2008 Share Posted March 22, 2008 Your while loop has some problems, it should be more like while($row = mysql_fetch_array($result)) { $d= $row['des']; if ($d = "beg") { echo "Beginning"; } if ($d = "end") { echo "End"; }} Of course, it could be possible that you have no row in that table where the des column equals "beg" or "end". Link to comment Share on other sites More sharing options...
Jetmatt777 Posted March 22, 2008 Author Share Posted March 22, 2008 Thanks man. It works like a charm now!Matt Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.