【发布时间】:2014-10-11 23:09:53
【问题描述】:
有一个 MySQL 数据库,带有 “事件”表。在该表中,我有超过 250 行,包含不同的事件、名称、ID、位置和开始时间。我知道如何从该表中获取所有数据,但我想学习如何获取特定行。
今天如何获取带有 start_time 的行?
我的代码:
//Create Database connection
$db = mysql_connect("####","####","####");
if (!$db) {
die('Could not connect to db: ' . mysql_error());
}
//Select the Database
mysql_select_db("rlidi37_timisoara",$db);
$result = mysql_query("select * from events", $db);
//Create an array
$json_response = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_array['name'] = $row['name'];
$row_array['location'] = $row['location'];
$row_array['id'] = $row['id'];
$row_array['start_time'] = $row['start_time'];
//push the values in the arr
array_push($json_response,$row_array);
}
echo json_encode($json_response);
//Close the database connection
fclose($db);
【问题讨论】:
-
是的...您应该使用
mysqli,mysql已折旧。面向对象的风格可以节省打字。你的问题太模糊了。 -
$result = mysql_query("select * from events where start_time>=CURDATE()", $db);