抱歉我的英文!
我认为我的问题很愚蠢,但我不知道怎么做。我有数据库字符串(u_liked)到сompleted(1 2 3),我需要这一行中的每个符号(数字),插入值和值插入查询。
if( isset($_GET["email"]) && !empty($_GET["email"]) ) {
$conn = new mysqli("mysql.hostinger.ru", "***", "***", "u858836722_testk");
$email=$_GET["email"];
$email = stripslashes($email);
$email = $conn->real_escape_string($email);
$check="SELECT u_liked FROM users WHERE u_id = '".$email."'";
//
$rs1 = mysqli_query($conn,$check);
$row = mysqli_fetch_assoc($rs1);
$row = stripslashes($row['u_liked']);
$row = $conn->real_escape_string($row);
// Don't work query
$query="SELECT p_id, p_name, p_description, p_image_id, p_price, p_add FROM products where p_id ='".$row."' ";
$result = $conn->query($query);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"p_id":"' . $rs["p_id"] . '",';
$outp .= '"p_name":"' . $rs["p_name"] . '",';
$outp .= '"p_description":"' . $rs["p_description"] . '",';
$outp .= '"p_image_id":"' . $rs["p_image_id"] . '",';
$outp .= '"p_price":"'. $rs["p_price"] . '",';
$outp .= '"p_add":"'. $rs["p_add"] . '"}';
}
$has_more=2;
$outp ='{"has_more":'.$has_more.',"records":['.$outp.']}';
$conn->close();
echo($outp);
}
但是当在数据库中写入一个字符时,我得到了
{"has_more":2,"records":[{"p_id":"3","p_name":"Готель: Кремінь","p_description":"Телефон: 05367 92300","p_image_id":"chicken_maharaja","p_price":"вулиця Ігоря Сердюка, 1, Кременчук, Полтавська область, 39605","p_add":"http://www.kreminhotel.com.ua/"}]}
这是工作
UPDATE 它正在运作!
if( isset($_GET["email"]) && !empty($_GET["email"]) ) {
$conn = new mysqli("mysql.hostinger.ru", "u858836722_testk", "80040163q", "u858836722_testk");
$email=$_GET["email"];
$email = stripslashes($email);
$email = $conn->real_escape_string($email);
$check="SELECT u_liked FROM users WHERE u_id = '".$email."'";
$rs1 = mysqli_query($conn,$check);
$row = mysqli_fetch_assoc($rs1);
$row = explode(' ',$row['u_liked']);
$row = array_map('intval',$row);
$query="SELECT p_id, p_name, p_description, p_image_id, p_price, p_add FROM products where p_id IN (".implode(',',$row).")";
$result = $conn->query($query);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"p_id":"' . $rs["p_id"] . '",';
$outp .= '"p_name":"' . $rs["p_name"] . '",';
$outp .= '"p_description":"' . $rs["p_description"] . '",';
$outp .= '"p_image_id":"' . $rs["p_image_id"] . '",';
$outp .= '"p_price":"'. $rs["p_price"] . '",';
$outp .= '"p_add":"'. $rs["p_add"] . '"}';
}
$has_more=2;
$outp ='{"has_more":'.$has_more.',"records":['.$outp.']}';
$conn->close();
echo($outp);
}