Kel196
Kel196

Reputation: 140

Simple MySQL if query syntax

edit: my table schema below is poorly normalized as suggested and I have revamped it.

schema

Upvotes: 0

Views: 267

Answers (2)

Milan Halada
Milan Halada

Reputation: 1934

Try to use mysql_num_rows() in your condition

if (mysql_num_rows($result) == 0) {
    echo (" It's NULL!");
    // if null, run a query!
} else {
echo (" It's not null...");
// if not null, echo back meessage saying not null.
}

EDIT: nevermind

EDIT2: Gosh, I see it now, try

$row = mysql_fetch_assoc($result);

if ($row[$userid] == NULL) {
    echo (" It's NULL!");
    // if null, run a query!
} else {
echo (" It's not null...");
// if not null, echo back meessage saying not null.
}

Upvotes: 2

user1269636
user1269636

Reputation:

Try using mysql_num_rows() for checking how many rows are returned,

if (mysql_num_rows($result) == 0)
{
    echo (" It's NULL!");
    // if null, run a query!
}
else
{
    echo (" It's not null...");
    // if not null, echo back meessage saying not null.
}

Also, what column are you trying to select ?

Upvotes: 1

Related Questions