提案がデータベースから来るオートコンプリートを使用していて、正常に動作していますが、mysqli に変更しようとしましたが、動作しません。提案は表示されません。エラーはありません。
- 私はmysqliの終わりに何が欠けていますか?
- テーブルをさらに追加するにはどうすればよいですか (40 個のテーブルがあります)。ありがとう。
MySQL:
<?php
mysql_connect("localhost","root","");
mysql_select_db("database");
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM products1 where title like '%".$term."%' order by id ");
$json=array();
while($student=mysql_fetch_array($query)){
$json[]=array(
'value'=> $student["title"],
'label'=>$student["title"]
);
}
echo json_encode($json);
?>
MySQLiの準備済みステートメントで試したこと:
<?php
$mydb = new mysqli('localhost', 'root', '', 'database');
$q = $_POST['term'];
$stmt = $mydb->prepare(" SELECT * from products1 where title LIKE ? ");
echo $mydb->error;
$stmt->bind_param('s', $q);
$stmt->execute();
?>
<?php
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$json[]=array(
'value'=> $student["title"],
'label'=>$student["title"]
);
}
echo json_encode($json);
?>