Javascript 在JSON文件中搜索
我正在现场表演 我使用它来获取json文件Javascript 在JSON文件中搜索,javascript,php,json,livesearch,Javascript,Php,Json,Livesearch,我正在现场表演 我使用它来获取json文件 <?php if(mysqli_num_rows($result) > 0) { while($row1 = mysqli_fetch_array($result)) { $output["name"][]=$row1["name"]; $output["email"][]=$row1["email"]; } } $fp = fopen('results.json', 'w'); fwrite(
<?php
if(mysqli_num_rows($result) > 0)
{
while($row1 = mysqli_fetch_array($result))
{
$output["name"][]=$row1["name"];
$output["email"][]=$row1["email"];
}
}
$fp = fopen('results.json', 'w');
fwrite($fp,json_encode($output));
fclose($fp);
?>
但是我需要下面的代码来进行搜索。有没有办法得到这样的JSON而不是上面的JSON?
或者我如何在上面的代码中搜索
[
{
"name":"Marinasy",
"email": "behambymarinasy@gmail.com"
},
{
"name":"Test",
"email": "test@test"
},
{
"name":"Nath",
"email": "nath@trs"
}
]
你可以这样做
<?php
$output= array();
if(mysqli_num_rows($result) > 0)
{
while($row1 = mysqli_fetch_array($result))
{
array_push($output, array('name'=> $row1["name"], 'email'=> $row1["email"]));
}
}
$fp = fopen('results.json', 'w');
fwrite($fp,json_encode($output));
fclose($fp);
?>
您可以这样做
<?php
$output= array();
if(mysqli_num_rows($result) > 0)
{
while($row1 = mysqli_fetch_array($result))
{
array_push($output, array('name'=> $row1["name"], 'email'=> $row1["email"]));
}
}
$fp = fopen('results.json', 'w');
fwrite($fp,json_encode($output));
fclose($fp);
?>
更改此选项
$output["name"][]=$row1["name"];
$output["email"][]=$row1["email"];
到
完整代码在这里
<?php
if (mysqli_num_rows($result) > 0) {
$output = [];
while ($row1 = mysqli_fetch_array($result)) {
$output[] = [
"name" => $row1["name"],
"email" => $row1["email"]
];
}
}
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($output));
fclose($fp);
?>
更改此选项
$output["name"][]=$row1["name"];
$output["email"][]=$row1["email"];
到
完整代码在这里
<?php
if (mysqli_num_rows($result) > 0) {
$output = [];
while ($row1 = mysqli_fetch_array($result)) {
$output[] = [
"name" => $row1["name"],
"email" => $row1["email"]
];
}
}
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($output));
fclose($fp);
?>
bruh,hide yo real info在哪里生成email
键?$output[“name”][=$row1[“name”]$输出[“电子邮件”][]=第1行[“电子邮件”];问题。您正在从数据库中的数据生成此JSON文件。为什么不搜索数据库呢?我通常会认为这是因为您正在将其发送给第三方,但在这种情况下不确定。我尝试在数据库中搜索,但不知道如何在结果上添加链接,这就是为什么我使用jsonbruh,hide yo real INFO在哪里生成电子邮件
键?$output[“name”[=$row1[“name”]$输出[“电子邮件”][]=第1行[“电子邮件”];问题。您正在从数据库中的数据生成此JSON文件。为什么不搜索数据库呢?我通常认为这是因为您将其发送给第三方,但在本例中不确定。我尝试在数据库中搜索,但不知道如何在结果上添加链接,这就是我使用jsonsolved的原因。。非常感谢你,因为这个问题我没睡。。非常感谢你,因为这个我没睡