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?
query if row in mysql empty, otherwise...
Moderator: General Moderators
-
gwolff2005
- Forum Commoner
- Posts: 68
- Joined: Sun Apr 05, 2009 10:58 am
Re: query if row in mysql empty, otherwise...
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
so the question now is, how to check if there is a result?
you do something like
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());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...
What your looking for is
Hope that helps
Code: Select all
/* query result */
$result = mysql_query("your query here ");
if (!empty($result)){
/* list your rows */
} else {
echo "No results to be displayed";
}
-
gwolff2005
- Forum Commoner
- Posts: 68
- Joined: Sun Apr 05, 2009 10:58 am
Re: query if row in mysql empty, otherwise...
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
and my code is:
What is wrong???
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'];Code: Select all
if (!empty(MM_resultsmo)){
echo "You need to do the test";
} else {
echo " " . $_SESSION['MM_resultsmo'];
}Re: query if row in mysql empty, otherwise...
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).
You can check with strlen() I think. The field will always be set, so empty() won't work (I don't think).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.