Chris Ginet Posted March 3, 2007 Share Posted March 3, 2007 Could anybody tell me if this code is correct, i get no errors but i get no output for it. $query2 = "IF ($OK=1) echo 'In Flight'; else echo ARRIVE ='$ARRIVEE'"; $result2 = mysql_query($query2); Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/ Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 What are you trying to do? What you have right now is too jumbled for me to understand. The syntax is wrong. Is there a database field named OK that you want to check? From there if it is equal to 1, you want it to say is in flight, otherwise it has arrived? Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198686 Share on other sites More sharing options...
Chris Ginet Posted March 3, 2007 Author Share Posted March 3, 2007 whast it needs to do is, when the feild OK is 1 it needs to say In Flight, If if its not 1, it needs to get the vaule that is in the field $ARRIVEE Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198688 Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 You would probably do something like this if you are working with a database <?php //Connect to Database $query = "Select * from TABLE"; // I don't know how many flights you have/want to change. This will do all of them. You might want to include a WHERE in the query to select only a specific flight $result = mysql_query($query) or die(mysql_error()); //Run query while($row = mysql_fetch_array($result)) //Loop through results { if($row['OK'] == 1) //If OK is equal to one... { echo "In Flight"; } else { echo $ARRIVEE; } } Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198690 Share on other sites More sharing options...
warewolfe Posted March 3, 2007 Share Posted March 3, 2007 if ($OK=1) is always true as it is true you have just assigned the value of 1 to the variable OK. Maybe you want ($OK == 1) $query2 = "IF ($OK==1) echo 'In Flight'; else echo ARRIVE ='$ARRIVEE'"; $result2 = mysql_query($query2); but even then $query2 doesn't look like any mysql query I've ever seen. Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198693 Share on other sites More sharing options...
Chris Ginet Posted March 3, 2007 Author Share Posted March 3, 2007 can the outcome of the IF statment be produced as a result as there is multiple records to be displayed so each record has the outcome Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198709 Share on other sites More sharing options...
Chris Ginet Posted March 3, 2007 Author Share Posted March 3, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198782 Share on other sites More sharing options...
LazyJones Posted March 3, 2007 Share Posted March 3, 2007 as warewolfe already said, $query2 doesn't even slightly resemble an SQL query Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198784 Share on other sites More sharing options...
Chris Ginet Posted March 3, 2007 Author Share Posted March 3, 2007 i have changed this now to the one JBS103 kindley told me about above. That is working. How can i get it to display as a result so i can put it on a table to show it for each of the records? Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198793 Share on other sites More sharing options...
coldkill Posted March 3, 2007 Share Posted March 3, 2007 Hello Chris, Haven't seen you in a while. Anywho onto the coding: You need to add in table code to the echo so: while($row = mysql_fetch_array($result)) //Loop through results { if($row['OK'] == 1) //If OK is equal to one... { $row .= "<tr><td>In Flight</td></tr>"; } else { $row .= '<tr><td>'.$ARRIVEE.'</td></tr>'; } } echo '<table>'.$row.'</table>'; Mike Quote Link to comment https://forums.phpfreaks.com/topic/41030-code-not-working/#findComment-198805 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.