Tech Support Guy banner

PHP If then else statement

1107 Views 2 Replies 3 Participants Last post by  JiminSA
Hi,
I need to retrieve data from a mysql database (that part im fine with), then depending on what data is returned basically echo back yes/no or maybe..

for example -

If the data pulled from the database is "hello world" I need it to echo "Yes"
If the data pulled from the database is "hello" I need it to echo "No"
And if anything else is pulled from the database else echo "maybe"

The code is always looking at the same row, in the same table of the database.
Status
Not open for further replies.
1 - 3 of 3 Posts
You can use the switch & case statement.

See http://www.w3schools.com/php/php_switch.asp

Read your database variable first as per the example.
Or if you want to go the if then else route ...
PHP:
/******** assuming that the entry in the database has been placed in $db_pull ... */

	if($dbpull=="hello world")
	{
		echo "Yes"
	}
	else
	{
		if($dbpull=="hello")
		{
			echo "No";
		}
		else
		{
			echo "maybe";
		}
	}
See less See more
1 - 3 of 3 Posts
Status
Not open for further replies.
Top