开发者

mysql_fetch_array() expects parameter 1 to be resource [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given” error while trying to create a php shopping cart

<?php
//connect to MYSQL
$con=mysql_connect("localhost","root","");
if (!$con)
{
          die ('cannot connect:'.mysql_error());
}

//to show the original message
mysql_select_db("tracking", $con);

$result = "SELECT lat, lng, DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime FROM markers1 WHERE 1";
if (!$result) { // add this check.
    die('Invalid query: ' . mysql_error());
}


echo "<table border='1'>
<tr>

<th>id No</th>
<th>lat Time</th>
<th>lng</th>
<th>datetime</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['lat'] . "</td>";
  echo "<td>开发者_如何学运维;" . $row['lng'] . "</td>";
  echo "<td>" . $row['datetime'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

It show me mysql_fetch_array() expects parameter 1 to be resource.

Can anyone help me .thx.


You're not running the query, it's only being stored in a string called $result. Here is the function you need: http://php.net/mysql_query


You aren't actually making a query...

Make the line...

$result = mysql_query("SELECT lat, lng, DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime FROM markers1 WHERE 1");


You need to call mysql_query to execute the query string. You also have a number of other problems with your code (the least of which is parameter binding.)


try this $result = mysql_query( "SELECT lat, lng FROM markers1 WHERE 1" );

You need to call the mysql_query() function first before you can call any fetch function such as mysql_fetch_array()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜