Question

I need something like:

$variable = mysql_query("Search name='Jane' and if you find it return boolean")

Exists some SQL command for this?

I hope that my question is understandable. Thanks.

Était-ce utile?

La solution

Yes,there is.

$query = mysqli_query("SELECT name FROM tableName WHERE name='Jane'");

This will return a boolean,so after that you can do something like

if ($query) {
    //do something
}
else {
    // do something else
}

Autres conseils

Checkout examples in php.net http://bg2.php.net/mysql_query

You can do

<?php 
/*** Some code here  and including , init connection to  database */
$variable = mysql_query("SELECT * FROM  table WHERE  name='Jane' ");

if($variable && mysql_num_rows($variable) != 0 ) 
{
/** TO DO ... If you have result */ 
} else { 
/**  TO TO OTHER ... if you have no result **/
}

But if you use mysql_num_rows (which depricated) and checkout for couting results different than zero. Also you can use SQL_CALC_FOUND_ROWS , you can find more information about this and performance here -> http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top