Home >Backend Development >PHP Tutorial >Warning: mysql_fetch_assoc() expects parameter 1 to be resou_PHP教程
I encountered the arning today: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in. Let’s take a look at the solution.
I encountered this error when I was learning PHP today:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:xampphtdocsmyblogindex.php on line 15
The source code is:
The code is as follows
|
Copy code
|
||||||||
$sql="select entries.*,categories.cat from entries,categorie where entries.cat_id=categories.id order by dateposted desc limit 1;"; $result=mysql_query($sql);
echo " " . $row['subject'] . "< /h2> |
The code is as follows
|
Copy code |
$sql="select entries.*,categories.cat from entries,categorie where entries.cat_id=categories.id order by dateposted desc limit 1;"; $result=mysql_query($sql); |
if($result){
"; echo nl2br($row['body']); echo "
"; } else{ echo "No article"; } ?> This way there will be no errors! -------------------------------------------------- -------------------------------------------------- ---------------------------------- Note: mysql_fetch_assoc() function Definition and usage The mysql_fetch_assoc() function fetches a row from the result set as an associative array. Returns an associative array based on the rows taken from the result set, or false if there are no more rows. Grammar mysql_fetch_assoc(data) parameter description data required. The data pointer to use. The data pointer is the result returned from mysql_query(). Tips and Notes Note: mysql_fetch_assoc() is exactly the same as using mysql_fetch_array() plus the second optional parameter MYSQL_ASSOC. It just returns an associative array. This is also how mysql_fetch_array() initially works. Tip: If you need a numeric index in addition to a relational index, use mysql_fetch_array(). Note: The field names returned by this function are case-sensitive.