Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从哪里选择困难?_Php_Mysql - Fatal编程技术网

Php 从哪里选择困难?

Php 从哪里选择困难?,php,mysql,Php,Mysql,我有这个代码,但奇怪的是,它总是回显“是!”,即使FLD2中没有像“555”这样的值,或者即使根本没有FLD2 $testresult = mysqli_query($database, "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'"); if ( $testresult ) { echo('yes!'); } else { echo('no!'); } 任何想法,谢谢 除非查询以某种方式失败,否则mysqli\u查询始终返回结果

我有这个代码,但奇怪的是,它总是回显“是!”,即使FLD2中没有像“555”这样的值,或者即使根本没有FLD2

$testresult = mysqli_query($database, "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'");

if ( $testresult ) { echo('yes!'); } else { echo('no!'); }

任何想法,谢谢

除非查询以某种方式失败,否则mysqli\u查询始终返回结果对象。如果查询没有返回任何行,仍然会得到一个结果对象;它只是没有任何行。

mysqli\u query总是返回一个结果对象,除非查询以某种方式失败。如果查询没有返回任何行,仍然会得到一个结果对象;它只是没有任何行。

您正在测试
$testresult
是否为真,而不是它们是否是查询的预期结果。如果查询是有效的,即格式良好,它将返回一个有效的对象。您需要查看
$testresult
返回值以查看是否找到了内容。

您正在测试的是
$testresult
是否为真,而不是它们是否为查询的预期结果。如果查询是有效的,即格式良好,它将返回一个有效的对象。您需要查看
$testresult
返回值以查看是否找到了什么。

正如ctshryock所述,当作为布尔对象查看时,设置为格式良好的SQL查询返回值的变量将始终被视为true

要测试是否返回了任何数据,可以使用
mysql\u num\u rows()
,它将返回返回的行数。如果查询与任何行都不匹配,则此函数应返回0,该值将被
If()
条件视为false

$testresult = mysql_query( "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'" );

if( !$testresult )
  die( 'SQL Error' ); # The SQL Query Failed for some reason

if( mysql_num_rows( $testresult ) )
  die( 'SQL Returned No Result' ); # The SQL Query returned nothing

while( $r = mysql_fetch_assoc( $testresult ) ) {
  # Process your returned rows here
}

正如ctshryock所述,当作为布尔对象查看时,设置为格式良好的SQL查询返回值的变量将始终被视为true

要测试是否返回了任何数据,可以使用
mysql\u num\u rows()
,它将返回返回的行数。如果查询与任何行都不匹配,则此函数应返回0,该值将被
If()
条件视为false

$testresult = mysql_query( "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'" );

if( !$testresult )
  die( 'SQL Error' ); # The SQL Query Failed for some reason

if( mysql_num_rows( $testresult ) )
  die( 'SQL Returned No Result' ); # The SQL Query returned nothing

while( $r = mysql_fetch_assoc( $testresult ) ) {
  # Process your returned rows here
}

THNAKS,现在它起作用了$testresult=mysqli_查询($database,“从imei359327039828680中选择*,其中FLD2='555')$testrow=mysqli\u fetch\u数组($testresult);如果($testrow){echo('yes!');}否则{echo('no!');}THNAKS,现在它工作了$testresult=mysqli_查询($database,“从imei359327039828680中选择*,其中FLD2='555')$testrow=mysqli\u fetch\u数组($testresult);if($testrow){echo('yes!');}else{echo('no!');}