我可以像在这里一样在mysql中使用where和order by
$results=mysql_query("SELECT `status_content`
FROM `status`
WHERE `user_id`=".$_SESSION['user_id']."
ORDER BY `status_time` DESC" );
她是我的代码,但它给了我错误
警告:mysql_fetch_array()要求参数1为资源,第65行的C:\ xampp \ htdocs \ lr \ profile.php中给出布尔值
<?php
$results=mysql_query("SELECT status_content FROM status
WHERE user_id=".$_SESSION['user_id']."
ORDER BY status_time DESC" );
while($row=mysql_fetch_array($results)) {
echo $row['status_content'];
}
?>
答案 0 :(得分:1)
是的,这是有效的,因为谷歌会告诉你http://dev.mysql.com/doc/refman/5.0/en/select.html
对于您的实际错误,from the php docs:
对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()会在成功时返回资源,或者在出错时返回FALSE。
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
// do something
}