我是 php 的超级新手,所以我需要一些帮助。我玩得很开心……我知道这很简单!
我在这里有一个 php 文件:http: //theclackamasprint.net/json.php
它将信息从 mysql 提取到 json。
我想要一个解析 URL 以通过它们的 catid 分隔文章(未显示)
所以我希望能够输入 http://theclackamasprint.net/json.php?catid=84 http://theclackamasprint.net/json.php?catid=87
等等......只有那些猫秀
这是我的代码:
$host = "******";
$db = "******";
$user = "******";
$pass = "******";
$connection = mysql_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}
else
{
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}
else
{
$query = "SELECT title FROM tcp_content WHERE catid=84 ORDER BY publish_up DESC LIMIT 20";
$resultset = mysql_query($query, $connection);
$records = array();
//Loop through all our records and add them to our array
while($r = mysql_fetch_assoc($resultset))
{
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
}
}