Jump to content

[SOLVED] if query returns something does it return true???


denoteone

Recommended Posts

I am checking a database to see if a variable is in there if it is I want to do something.  Am I on the right track here?  the varible $row['visitor_whois'] changes because this is part of a bigger while statement.

 

	
$query  = "SELECT * FROM isp WHERE name  = $row['visitor_whois']";
$result = mysql_query($query)or die (mysql_error());

    if( $result == "true"){

}

<?php
$query  = "SELECT * FROM isp WHERE name  = '{$row['visitor_whois']}'";
$result = mysql_query($query)or die (mysql_error());

while ($row = mysql_fetch_assoc($result)) {
     if( $row['column_name'] == "true" ){

     }
}

 

Change column_name to the column name you want to compare the value to.

 

But if you only want to compare it to the value true, you can use this SQL:

<?php
$query  = "SELECT * FROM isp WHERE name  = '{$row['visitor_whois']}' AND column_name = 'true'";
$result = mysql_query($query)or die (mysql_error());

while ($row = mysql_fetch_assoc($result)) {
     // do your stuff here
}

 

That will select all rows where name = some name and the specified column_name value is true.

Hi

 

If nothing is returned but query has still worked then it will return true. False will be returned if there is an error.

 

$query  = "SELECT * FROM isp WHERE name  = '".$row['visitor_whois']."'";
$result = mysql_query($query)or die (mysql_error());
if( mysql_fetch_array($result))
{
// Some code here
}

 

or if you do not care about any data returned and just want to know some is:-

 

$query  = "SELECT * FROM isp WHERE name  = '".$row['visitor_whois']."'";
$result = mysql_query($query)or die (mysql_error());
if( mysql_num_rows($result) > 0)
{
// Some code here
}

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.