【发布时间】:2017-01-07 10:03:26
【问题描述】:
我有如下所示的 api 代码,最近它根据我的要求显示,但对于 cid 和帮助,我需要与最新的相同(必须首先显示最近的)。我的代码如下谢谢
<?php include("includes/connection.php");
mysql_query("SET NAMES 'utf8'");
if(isset($_GET['language_id']))
{
$query="SELECT cid,category_name,category_image FROM tbl_category WHERE lid='".$_GET['language_id']."'";
}
else if(isset($_GET['cat_id']))
{
$cat_id=$_GET['cat_id'];
$query="SELECT * FROM tbl_quotes
LEFT JOIN tbl_category ON tbl_quotes.cat_id= tbl_category.cid
where tbl_quotes.cat_id='".$cat_id."'";
}
else if(isset($_GET['latest']))
{
$limit=$_GET['latest'];
$query="SELECT * FROM tbl_quotes
LEFT JOIN tbl_category ON tbl_quotes.cat_id= tbl_category.cid
ORDER BY tbl_quotes.id DESC LIMIT $limit";
}
else if(isset($_GET['home_banner']))
{
$query="SELECT app_name,app_url,app_image FROM tbl_banner";
}
else if(isset($_GET['about_app']))
{
$query="SELECT app_name,app_logo,app_email,app_website,app_description FROM tbl_settings";
}
else
{
$query="SELECT id,language_name FROM tbl_language";
}
$resouter = mysql_query($query);
$set = array();
$total_records = mysql_num_rows($resouter);
if($total_records >= 1){
while ($link = mysql_fetch_array($resouter, MYSQL_ASSOC)){
$set['Quotes'][] = $link;
}
}
else
{
$set['Quotes'][] = null;
}
header( 'Content-Type: application/json; charset=utf-8' );
echo $val= str_replace('\\/', '/', json_encode($set));
对此进行了实验性修改,但无济于事
else if(isset($_GET['cat_id']))
{
$cat_id=$_GET['cat_id'];
$query="SELECT * FROM tbl_quotes
LEFT JOIN tbl_category ON tbl_quotes.cat_id= tbl_category.cid
where tbl_quotes.cat_id='".$cat_id."'";
}
试试这个也成功了php mysql sort by date (Recent)
这是链接api/api.php?cat_id=1
【问题讨论】:
-
这样使用 $query="SELECT cid,category_name,category_image FROM tbl_category WHERE lid='".$_GET['language_id']."' order by cid DESC";
-
mysql-* 已弃用尝试使用 mysqli_*