<? $host="localhost"; $user="root"; $pwd=""; $data="mysql"; mysql_connect($host,$user,$pwd)or die("找不到服务器!"); mysql_select_db($data)or die("找不到数据库!"); $f=mysql_query("select count(id) from user where host like '%$messag%'"); $num=mysql_fetch_array($f); if($f) {echo"搜到$num条记录";}else{echo"没有找到你需要的记录!";} ?>为什么这个还是不对,错误信息如下: Warning: Supplied argument is not a valid MySQL result resource in e:\web\find\find.php on line 9 没有找到你需要的记录!
$f = @mysql_query("select * from user where host like '%$messag%'"); $num = @mysql_fetch_array($f);再说,你这个$messag是个变量吧,它有没有值呀!
$f = @mysql_query("select * from user where host like '".%$messag."%'");试试看.
我觉得是,你没有给指出连接到哪个数据库中 试试这个 <? $host="localhost"; $user="root"; $pwd=""; $data="mysql"; $DB=mysql_connect($host,$user,$pwd)or die("找不到服务器!"); mysql_select_db("要连接的数据库",$DB)or die("找不到数据库!"); $f=mysql_query("select count(id) from user where user like '%$messag%'",$DB); $num=mysql_fetch_array($f); ?>
调用mysql_query时,不用必须指出连接到哪个数据库,MYSQL会自动连接到最近打开的数据库。 改改这句试试看: $f = @mysql_query("select * from user where host like '%".$messag."%'");
这是我给你修改以后的代码.<? $host="localhost"; $user="root"; $pwd=""; $data="hooday"; $messag="1"; $id = mysql_connect($host,$user,$pwd)or die("找不到服务器!"); mysql_select_db($data)or die("找不到数据库!"); $sql = "select count(*) as aaa from user where host like '%$messag%'"; $f=mysql_query($sql); $num=mysql_fetch_array($f); $n= $num['aaa']; if($n) {echo "搜到".$n."条记录";}else{echo"没有找到你需要的记录!";} ?>应该能运行了.你试试.
$host="localhost";
$user="root";
$pwd="";
$data="mysql";
mysql_connect($host,$user,$pwd)or die("找不到服务器!");
mysql_select_db($data)or die("找不到数据库!");
$f=mysql_query("select count(id) from user where host like '%$messag%'");
$num=mysql_fetch_array($f);
if($f)
{echo"搜到$num条记录";}else{echo"没有找到你需要的记录!";}
?>为什么这个还是不对,错误信息如下:
Warning: Supplied argument is not a valid MySQL result resource in e:\web\find\find.php on line 9
没有找到你需要的记录!
$num = @mysql_fetch_array($f);再说,你这个$messag是个变量吧,它有没有值呀!
试试这个
<?
$host="localhost";
$user="root";
$pwd="";
$data="mysql";
$DB=mysql_connect($host,$user,$pwd)or die("找不到服务器!");
mysql_select_db("要连接的数据库",$DB)or die("找不到数据库!");
$f=mysql_query("select count(id) from user where user like '%$messag%'",$DB);
$num=mysql_fetch_array($f);
?>
改改这句试试看:
$f = @mysql_query("select * from user where host like '%".$messag."%'");
$host="localhost";
$user="root";
$pwd="";
$data="hooday";
$messag="1";
$id = mysql_connect($host,$user,$pwd)or die("找不到服务器!");
mysql_select_db($data)or die("找不到数据库!");
$sql = "select count(*) as aaa from user where host like '%$messag%'";
$f=mysql_query($sql);
$num=mysql_fetch_array($f);
$n= $num['aaa'];
if($n)
{echo "搜到".$n."条记录";}else{echo"没有找到你需要的记录!";}
?>应该能运行了.你试试.