0

I just trying to show a result of a consult in MySQL (PHP). The code is:

$example = mysql_query("SELECT count(*) as text FROM table WHERE name = '$name'");
$qtd = mysql_num_rows($example);
while($data = mysql_fetch_array($qtd)){
$count = $data["text"];
}

echo "<h3>($count)</h3>";

Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\Site\index.php on line 9

4

2 に答える 2

1

CHANGE THIS

 while($data = mysql_fetch_array($qtd)){
 $count = $data["text"];
 }

to

while($data = mysql_fetch_array($example)){
 $count = $data["text"];
  }

EDIT : you dont need to do a while loop here.

you should just do like that

     $example = mysql_query("SELECT count(*) as text FROM table WHERE name = '$name'");
     $data = mysql_fetch_array($example) ;
     $count = $data["text"];
     echo "<h3>".$count."</h3>";
于 2013-03-10T19:13:17.763 に答える
0

This should work, you don't need to use a while statement.

$query = mysql_query("SELECT * FROM table WHERE name = '$name'");
$count = mysql_num_rows($query);
echo $count;
于 2013-03-10T19:26:32.510 に答える