StealthRT
StealthRT

Reputation: 10542

mySQL seeing if row exist

Hey all i have the following code:

$query = "SELECT * " .
            "FROM wp_postmeta " .
            "WHERE post_id = " . $postID . " " .
            "AND meta_key = 'xTraData';";
$result = mysql_query($query);

echo $result;
    echo '    ' . $postID;

if($result >= 1){

And i am returned Resource id #2 for the $result....

enter image description here

There are no rows for that. Its all null when running the query SELECT * FROM wp_postmeta WHERE post_id = 1792 AND meta_key = 'xTraData';

enter image description here

And i made sure that $postID was returning 1792 and it is.

I was thinking it would return a 0 or 1...

Upvotes: 0

Views: 67

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

You need to use mysql_fetch_assoc($result), possibly like so:

while ($row = mysql_fetch_assoc($result)) {
    echo $row['postID'];
}

Don't use ext/mysql. Use PDO or mysqli.

Upvotes: 1

Related Questions