php - 如何使用单个查询创建多个搜索字段? [PHP/HTML]

标签 php html

我正在使用 API curl 方法获取 JSON 数据,然后将其插入到我的网络应用程序的 HTML 格式表格中。

我的需求略有变化,现在我需要在一次搜索中搜索多个票号。这是我目前拥有的..

 <form action="http://-withheld-/shop/ticket.php" method="GET">
    <input type="text" name="id" placeholder="Search by TicketID" required="required"><br>

    <button type="submit">Search</button><br>

我尝试添加更多字段但无济于事。

即)

<input type="text" name="id1" placeholder="Search by TicketID" required="required"><br>
<input type="text" name="id2" placeholder="Search by TicketID" required="required"><br>
<input type="text" name="id3" placeholder="Search by TicketID" required="required"><br>

哦,还有,这是我的代码的 php 部分,目前用于在搜索时获取单个票证 ID。

if(isset($_GET['id'])) {
        $id = $_GET['id'];
    }

我试图用上面的 HTML 代码和下面的代码添加更多字段:

if(isset($_GET['id'])) {
$id = $_GET['id1'];
$id = $_GET['id2'];
$id = $_GET['id3'];

        }

等等。如果有人能帮我解决这个问题,我将不胜感激。我知道这是一个非常基本的问题,但我无法找到有关使用 $_GET 方法查询多个搜索的任何细节。我发现的所有内容都与 MYSQL 查询有关。

提前感谢您的宝贵时间和帮助!

最佳答案

形式:

<form action="http://-withheld-/shop/ticket.php" method="GET">
 <input type="text" name="id1" placeholder="Search by TicketID" required="required"><br>
 <input type="text" name="id2" placeholder="Search by TicketID" required="required"><br>
 <input type="text" name="id3" placeholder="Search by TicketID" required="required"><br>

<button type="submit">Search</button><br>

收集表单数据并查询json数据:

if(isset($_GET['id1'])) {
$id1 = $_GET['id1'];
$url1 = 'http://-withheld-/api/v1/tickets/'.$id1.'?api_key=0f8797897-ba73-40bb-9b74-366ef‌​03c2cbf'; 
// Initiate curl 
$ch1 = curl_init(); 
// Disable SSL verification 
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch1, CURLOPT_URL,$url1); 
// Execute 
$result1=curl_exec($ch1); 
// Closing 
curl_close($ch1); 
// Will dump a beauty json :3 
$jsonObj1 = json_decode($result1);
}
if(isset($_GET['id2'])) {
$id2 = $_GET['id2'];
$url2 = 'http://-withheld-/api/v1/tickets/'.$id2.'?api_key=0f8797897-ba73-40bb-9b74-366ef‌​03c2cbf'; 
// Initiate curl 
$ch2 = curl_init(); 
// Disable SSL verification 
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch2, CURLOPT_URL,$url2); 
// Execute 
$result2=curl_exec($ch2); 
// Closing 
curl_close($ch2); 
// Will dump a beauty json :3 
$jsonObj2 = json_decode($result2);
}
}
if(isset($_GET['id3'])) {
$id3 = $_GET['id3'];
$url3 = 'http://-withheld-/api/v1/tickets/'.$id3.'?api_key=0f8797897-ba73-40bb-9b74-366ef‌​03c2cbf';
// Initiate curl 
$ch3 = curl_init(); 
// Disable SSL verification 
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch3, CURLOPT_URL,$url3); 
// Execute 
$result3=curl_exec($ch3); 
// Closing 
curl_close($ch3); 
// Will dump a beauty json :3 
$jsonObj3 = json_decode($result3);
}
}

然后显示结果:

if(isset($jsonObj1)){
foreach ($jsonObj1->{'tickets'} as $ticket1) { 
echo '<tr>'; echo '<td>'.$ticket1->{'id'}.'</td>'; echo '<td>'.$ticket1->{'number'}.'</td>'; echo '<td>'.$ticket1->{'customer_business_then_name'}.'</td>'; echo '<td>'.$ticket1->{'subject'}.'</td>'; echo '<td>'.$ticket1->{'created_at'}.'</td>'; echo '<td>'.$ticket1->{'status'}.'</td>'; echo '<td>'.$ticket1->{'problem_type'}.'</td>'; echo '<td>'.$ticket1->{'updated_at'}.'</td>'; echo '<td><a href="'.$link_addr.'">View</a></td>'; echo '<html></tr></html>';
}
}

if(isset($jsonObj2)){
foreach ($jsonObj2->{'tickets'} as $ticket2) { 
echo '<tr>'; echo '<td>'.$ticket2->{'id'}.'</td>'; echo '<td>'.$ticket2->{'number'}.'</td>'; echo '<td>'.$ticket2->{'customer_business_then_name'}.'</td>'; echo '<td>'.$ticket2->{'subject'}.'</td>'; echo '<td>'.$ticket2->{'created_at'}.'</td>'; echo '<td>'.$ticket2->{'status'}.'</td>'; echo '<td>'.$ticket2->{'problem_type'}.'</td>'; echo '<td>'.$ticket2->{'updated_at'}.'</td>'; echo '<td><a href="'.$link_addr.'">View</a></td>'; echo '<html></tr></html>';
}
}

if(isset($jsonObj3)){
foreach ($jsonObj3->{'tickets'} as $ticket3) { 
echo '<tr>'; echo '<td>'.$ticket3->{'id'}.'</td>'; echo '<td>'.$ticket3->{'number'}.'</td>'; echo '<td>'.$ticket3->{'customer_business_then_name'}.'</td>'; echo '<td>'.$ticket3->{'subject'}.'</td>'; echo '<td>'.$ticket3->{'created_at'}.'</td>'; echo '<td>'.$ticket3->{'status'}.'</td>'; echo '<td>'.$ticket3->{'problem_type'}.'</td>'; echo '<td>'.$ticket3->{'updated_at'}.'</td>'; echo '<td><a href="'.$link_addr.'">View</a></td>'; echo '<html></tr></html>';
}
}

关于php - 如何使用单个查询创建多个搜索字段? [PHP/HTML],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37558161/

相关文章:

html - 使用 XPATH 获取 HTML 标签的类名

Php本地主机重定向到/var/www/html/index.php

php - 如何从 PHP 调用 MySQL 交互式客户端?

css - FontAwesome 5 图标堆栈与标准图标不一致

javascript - 如何简化 Javascript "show/hide on DIV"函数的代码?

html - 如何在 Ionic 应用程序中保持相同的标题部分?

java - 动态添加html选择到表单

javascript - 通过提交按钮将 PHP 转换为 JavaScript

php - 多对多实体选择查询 Doctrine

php - 更改 Zend_Framework 项目中的公用文件夹位置?