I know this is really simple but I am not getting the syntax correct. I have a page that is already connected to the database. The way this script is written, the contents of a particular field (pd) in the table will always be 0 or 1. I am trying to write, if the contents of field "pd" is "1" then "x" else "y" Can someone post how I would do that? Right now, I have: if ( $pd == 1 ) { //do this }else{ //do that } Code (markup): I think the problem is how I am fetching the data. I think that is the part I am screwing up with. Any thoughts please?
You're not giving us all the details. If you get an error please paste it here. Also, you might want to use _strict_ SQL statements, although I doubt this is the problem: $SQL = "SELECT * from MANUAL where PD='$pd'"; - vs - $SQL = "SELECT * from `MANUAL` where `PD`='$pd'"; Code (markup):
Perhaps something like this? $sql = "SELECT * FROM `manual`"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { if ($row['pd'] == 1) { echo "x"; //do this } else { echo "y"; //do that } } PHP:
The code you pasted is perfectly valid. Make sure you're DB is designed the way your script works, test the following and let us know if you get any error: $sql = "SELECT * FROM `manual`"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($res)) { if ($row['pd'] == 1) { echo "x"; //do this } else { echo "y"; //do that } } Code (markup):