tags:

views:

52

answers:

3

I was wondering how can you check to see if certain data is present in a database and if so display it on the web page and if not don't display it using PHP.

+1  A: 

You select the data and you can use mysql_num_rows() to check how many rows were returned.

If no rows are returned, you can do something else.

Rough unsafe example

$query = mysql_query("SELECT * FROM users WHERE id = 20");
$num = mysql_num_rows($query);

if($num > 0)
{
    // Stuff to do when you find the items
}
else
{
    // No items found
}
Ólafur Waage
A: 

That's a pretty involved question. It requires you to connect to your database mysql_connect(), query it mysql_query(), and pour out any results from the query mysql_fetch_object().

Jonathan Sampson
A: 

Using the PHP MySQL interface functions, you run a SQL SELECT query that will retrieve the data you are looking for. Using a PHP control structure such as if, you then conditionally display the data, or not, depending on its existence or lack thereof.

chaos