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"){

}

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.