这是我检索信息并发送回 ajax 的代码:
else if(isset($_POST['act']) && $_POST['act']=='getbook'){
$book = normalize_str(htmlentities(preg_replace('/\s+/',' ', $_POST['book']), ENT_QUOTES,'UTF-8'));
$filecat = '../books/'.$book.'/'.$book.'.txt';
$catlist = file($filecat, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
$stmt = $mysqli->stmt_init();
$query = "SELECT `id`,`title`,`price`,`image`,`description`,`category`,`enablerating`,`rating` FROM ".$PapierTableName." WHERE book = ? ORDER BY position ASC, title ASC;";
$prepared = $stmt->prepare($query);
if($prepared){
$stmt->bind_param('s', $book);
$stmt->execute();
$result = $stmt->bind_result($iden, $title, $price, $image, $description, $category, $enrat, $rating);
if($result)
{
$rit = array();
while($stmt->fetch())
{
$rit[] = array(
invert_str(html_entity_decode($title, ENT_QUOTES, 'UTF-8')),
$price,
invert_str(html_entity_decode($image, ENT_QUOTES, 'UTF-8')),
invert_str(html_entity_decode($description, ENT_QUOTES, 'UTF-8')),
invert_str(html_entity_decode($category, ENT_QUOTES, 'UTF-8')),
$enrat,
$rating,
$iden
);
}
$stmt->close();
$count = count($catlist);
$ret = array();
for($i = 0; $i < $count ; $i++)
$ret= array_merge($ret, search($rit, 4, $catlist[$i]));
file_put_contents('tre.txt',print_r($ret,true));
echo json_encode($ret);
}
else
file_put_contents('binderror.txt', $stmt->error);
}
else
file_put_contents('connecterror.txt',$stmt->error);
}
我的问题是,如果我添加$iden
到数组中它不再起作用,我的意思是我没有数组,如果我用 print_r 打印它我没有输出。我也尝试过使用(string)$iden
我可以连接到数据库,并且所有信息都已检查(值和存在)
没有
附加信息。$iden
Array
(
[0] => Array
(
[0] => DB9
[1] => 200031
[2] => //localhost/css/images/objectimg/Aston Martin/db9.jpg
[3] => some html
[4] => DB9
[5] => 1
[6] => 0
)
[1] => Array
(
[0] => Rapid S
[1] => 200000
[2] => //localhost/css/images/objectimg/Aston Martin/vanq.jpg
[3] => some html
[4] => Rapid S
[5] => 1
[6] => 0
)
)
和$iden
Array
(
)
最后$iden
:
Array
(
[0] => Array
(
[0] => DB9
[1] => 200031
[2] => //localhost/css/images/objectimg/Aston Martin/db9.jpg
[3] => some html
[4] => DB9
[5] => 1
[6] => 0
[7] => 42
)
[1] => Array
(
[0] => Rapid S
[1] => 200000
[2] => //localhost/css/images/objectimg/Aston Martin/vanq.jpg
[3] => some html
[4] => Rapid S
[5] => 1
[6] => 0
[7] => 45
)
)