Skip to content
Advertisement

get data from API token to php table

i have an API that has around 1030 json objects, i need to findfew of them by search and show below only the one that matches my search, how can i do that? thank you for response

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Campaign Exclude App</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<h1>Campaigns</h1><br>
<input type="text" name="" id="">
<input type="submit">
<table class="table">
  <thead class="thead-dark">
    <tr>
      <th scope="col">Id</th>
      <th scope="col">Campaign Name</th>
      <th scope="col">CPA Goal</th>
      <th scope="col">Click Amount</th>
    </tr>
  </thead>
</table>

<?php
$url='https://www.popads.net/api/campaign_list?key=xxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$resultArray = json_decode($result);
echo "<pre>";
print_r($resultArray);
?>
</body>
</html>

Advertisement

Answer

this is simple example how you can loop $resultArray with foreach, so you can find any object by the name:

$resultArray = json_decode($result);

$name = "type the name you looking for";

$myArray = array();
foreach ($resultArray as $val){
    if ($val->name == $name){
        $myArray[] = $val;
    }
}

print_r($myArray); // print what you find
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement