表单:
<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-366ef03c2cbf';
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_URL,$url1);
$result1=curl_exec($ch1);
curl_close($ch1);
$jsonObj1 = json_decode($result1);
}
if(isset($_GET['id2'])) {
$id2 = $_GET['id2'];
$url2 = 'http://-withheld-/api/v1/tickets/'.$id2.'?api_key=0f8797897-ba73-40bb-9b74-366ef03c2cbf';
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_URL,$url2);
$result2=curl_exec($ch2);
curl_close($ch2);
$jsonObj2 = json_decode($result2);
}
}
if(isset($_GET['id3'])) {
$id3 = $_GET['id3'];
$url3 = 'http://-withheld-/api/v1/tickets/'.$id3.'?api_key=0f8797897-ba73-40bb-9b74-366ef03c2cbf';
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch3, CURLOPT_URL,$url3);
$result3=curl_exec($ch3);
curl_close($ch3);
$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>';
}
}