这是我的数据库结构和数据库数据
这是我的API
<?php
include("baseconfig/db_conection.php");
if(!empty($_GET['search']) && !empty($_GET['count']))
{
$search=$_GET['search'];
$count=$_GET['count'];
if(strcasecmp((substr("$count", -1)),'S') == 0)
{
$num=explode('s', $count);
$number=$num[0];
if(strcasecmp($search, 'ALL') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'A-D') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[A-D].*$' AND smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'E-I') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[E-I].*$' AND smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'J-O') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[J-O].*$' AND smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'P-T') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[P-T].*$' AND smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'U-Z') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[U-Z].*$' AND smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
else
{
$query="SELECT * FROM `brandnew` ORDER BY smokename ASC";
}
}
else if(strcasecmp((substr("$count", -1)),'G') == 0)
{
$num=explode('g', $count);
$number=$num[0];
if(strcasecmp($search, 'ALL') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'A-D') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[A-D].*$' AND smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'E-I') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[E-I].*$' AND smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'J-O') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[J-O].*$' AND smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'P-T') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[P-T].*$' AND smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'U-Z') == 0 && is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[U-Z].*$' AND smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
else
{
$query="SELECT * FROM `brandnew` ORDER BY smokename ASC";
}
}
}
else if(!empty($_GET['search']))
{
$search=$_GET['search'];
if(strcasecmp($search, 'ALL') == 0)
{
$query="SELECT * FROM `brandnew` ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'A-D') == 0)
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[A-D].*$' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'E-I') == 0)
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[E-I].*$' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'J-O') == 0)
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[J-O].*$' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'P-T') == 0)
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[P-T].*$' ORDER BY smokename ASC";
}
else if(strcasecmp($search, 'U-Z') == 0)
{
$query="SELECT * FROM `brandnew` WHERE smokename REGEXP '^[U-Z].*$' ORDER BY smokename ASC";
}
}
else if(!empty($_GET['count']))
{
$count=$_GET['count'];
if(strcasecmp((substr("$count", -1)),'S') == 0)
{
$num=explode('s', $count);
$number=$num[0];
if(is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokeunit=$number AND smoketype='Cigratte' ORDER BY smokename ASC";
}
}
else if(strcasecmp((substr("$count", -1)),'G') == 0)
{
$num=explode('g', $count);
$number=$num[0];
if(is_numeric($number))
{
$query="SELECT * FROM `brandnew` WHERE smokeunit=$number AND smoketype='Tobacco' ORDER BY smokename ASC";
}
}
}
else if(empty($_GET['search']) && empty($_GET['count']))
{
$query="SELECT * FROM `brandnew` ORDER BY smokename ASC";
}
$run=mysqli_query($dbcon,$query);
$result=mysqli_affected_rows($dbcon);
$id=new \stdClass();
if($run && $result > 0)
{
while($row=mysqli_fetch_assoc($run))
{
$id->success='Yes';
$id->smoke[]=$row;
}
}
else if($run)
{
$id->success='Yes';
$id->smoke=NULL;
}
else
{
$id->success='No';
}
$myJSON=json_encode($id);
echo $myJSON;
?>
因此,当我尝试使用以下参数查询API时出现问题
localhost/smoke/api/allcallserviceapinew.php
localhost/smokes/api/allcallserviceapinew.php?search=all&count=all
localhost/smokes/api/allcallserviceapinew.php?search=all&count=20s
localhost/smokes/api/allcallserviceapinew.php?search=all&count=25g
我得到一个空白页面响应。以前我有这个问题,因此将所有字段都转换为utf8_bin格式(如图所示),但仍然没有响应。
尤其是查询P-T类别。
我也能够获得
的输出localhost/smokes/api/allcallserviceapinew.php?search=A-D&count=20s
localhost/smokes/api/allcallserviceapinew.php?search=E-I&count=20s
localhost/smokes/api/allcallserviceapinew.php?search=J-O&count=25g
无论查询出错还是数据损坏,我都完全迷失了。任何人都可以提供一些信息,指出哪里出了问题?
谢谢