Page 1 of 1
query if row in mysql empty, otherwise...
Posted: Tue Apr 14, 2009 10:09 am
by gwolff2005
Hi guys I need your help.
I need a code saying: If row "x", "y", "z" of table "user" in database" "guntmar" is empty display the following text "is empty" otherwise display the content as a graph.. How can i do that?
Re: query if row in mysql empty, otherwise...
Posted: Tue Apr 14, 2009 9:45 pm
by it2051229
ok i don't really get what you're saying there.. but I understood the "query if row in mysql is empty"..
let me give you an example, but i'm not going to make use of x y or z.
let's say I want to query all persons in the database with the name "john"...
so i do something like
Code: Select all
$johnQuery = mysql_query("SELECT name FROM persons WHERE name='JOHN' ") or die(mysql_error());
so the question now is, how to check if there is a result?
you do something like
Code: Select all
if(mysql_num_rows($johnQuery) > 0)
{
echo "There are ".mysql_num_rows($johnQuery)." john(s) queried.";
}
else
{
echo "There are no john queried.";
}
Re: query if row in mysql empty, otherwise...
Posted: Tue Apr 14, 2009 9:47 pm
by tech603
What your looking for is
Code: Select all
/* query result */
$result = mysql_query("your query here ");
if (!empty($result)){
/* list your rows */
} else {
echo "No results to be displayed";
}
Hope that helps
Re: query if row in mysql empty, otherwise...
Posted: Wed Apr 15, 2009 6:11 am
by gwolff2005
hi guys,
maybe something really simple, but i dont get it.
I declare variables at the beginning of the session. Later I want to show a graph to the user (if the data is in mysql), if they are not stored in mysql a text should come up, saying: "You need to do the test." Still it does not work.
My session variable is
Code: Select all
$_SESSION['MM_resultsmo'] = $row['resultsmo'];
and my code is:
Code: Select all
if (!empty(MM_resultsmo)){
echo "You need to do the test";
} else {
echo " " . $_SESSION['MM_resultsmo'];
}
What is wrong???
Re: query if row in mysql empty, otherwise...
Posted: Wed Apr 15, 2009 9:53 am
by pickle
It sounds like you're not checking if the
row is empty, but rather certain fields in a row.
You can check with
strlen() I think. The field will always be set, so
empty() won't work (I don't think).