这是objective-c代码
NSString *CategoryID = @"2";
NSString *strURL =[NSString stringWithFormat:@"http://****/iCategoryItems.php?CategoryID=%@",CategoryID];
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];
这是 icategoryitems.php 页面的 php 代码
$cid = $GET_["CategoryID"];
$sql = "SELECT * FROM items where cat_id = '".$cid."' ";
但是,按原样代码始终返回 cat_id = 0 的项目
我是发送类别ID的方式错误,还是从php错误的方式读取它!
我想你的意思是:
$cid = $_GET["CategoryID"];
^^^
你的代码也容易受到SQL注入攻击。您应该使用 PDO 进行查询:http://php.net/manual/en/book.pdo.php