Jump to content

Need some help with MySQL select


Jetmatt777

Recommended Posts

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

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

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

Archived

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

×
×
  • Create New...