1
I have a site in Wordpress and in it I am consuming a Web Service, I created a function to filter the championships based on some information:
Sex : M
Modality : 2
Category : 4
If they are all true, it returns the name of the respective championship, the problem is that if there is more than one championship with the same conditions, it displays all the names at once, as I do not have much experience with this type of function and it is the first time I consume a Web Service, I wonder if it would have how to display a championship per table line, so I can separate them in each "<a>"
using the jQuery script I created, thanks for the help!
Test.php
<?php
$api_request = 'https://sportsmanager.com.br/api/[email protected]&token=SLXSO8342HSDE78623GVS7234GNMSKL';
$api_response = wp_remote_get( $api_request );
$api_data = json_decode( wp_remote_retrieve_body( $api_response ), true );
$retorno = '';
if($api_data){
foreach($api_data as $row){
if(!is_array($row)){
//$retorno = $retorno.'<td>'.$row.'</td>';
}else{
if($row['sexo'] == 'M' && $row['modalidade'] == 2 && $row['categoria'] == 4){
$retorno .='<td>'.$row['nome'].'</td>';
}
}
}
}
?>
jQuery
$(function(){
var html = '<a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab"><?php echo $retorno;?></a>';
$('#myList').html(html);
});
Return of the url
{
"codigo": "1",
"nome": "1ª Fase",
"modalidade": "9",
"categoria": "10",
"sexo": "F",
"data": "2018-04-12 00:00:00",
"atualizacao": "2018-07-23 04:07:15",
"status": "N"
},
{
"codigo": "2",
"nome": "1ª Fase",
"modalidade": "2",
"categoria": "4",
"sexo": "M",
"data": "2018-04-05 00:00:00",
"atualizacao": "2018-07-20 01:07:40",
"status": "S"
},
{
"codigo": "14",
"nome": "50 metros Livre Nível A",
"modalidade": "304",
"categoria": "10",
"sexo": "F",
"data": "2018-05-20 00:00:00",
"atualizacao": null,
"status": "N"
},
{
"codigo": "15",
"nome": "CIRCUITO ESCOLAR - SÉRIE OURO",
"modalidade": "2",
"categoria": "4",
"sexo": "M",
"data": "2018-08-13 00:00:00",
"atualizacao": null,
"status": "N"
},
Miguel, since it’s an api you should consult the api documentation to see how you can return the data differently, there’s nothing we can help with that. If you want to manipulate the result, put in the answer an example of the return json and what you would like to change that we can help you
– Ricardo Pontual
I understand, I’m sorry, it’s my first time with this kind of work, I’ll post the return of Json, because they didn’t give me any documentation, I’m very lost! If you can help me, I’d be very grateful!
– Miguel Campos
Tranquil Miguel. Well the json is simple, now you need to explain it better: " would like to know if it would have how to display a championship per table line". I don’t know what parameters you used, but it didn’t seem to filter by those criteria you mentioned in the question, see that there are different modalities and categories in the result
– Ricardo Pontual
on that line, I make him compare three values, if($Row['sex'] == ’M' && $Row['mode'] == 2 && $Row['category'] == 4) {$return .= '<td>'. $Row['name']. '</td>'; and return me the name of the championship, but there is more than one championship that meets these criteria, so it returns the name of two of them in the same row, I would like each championship to have its own generated line within this html tag <a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab"><? php echo $return;? ></a>
– Miguel Campos
the result is general, it would filter differently according to the page, but then I would change the values as needed.
– Miguel Campos
i just need it to divide the filtered names and display each one in its <a class="list-group-item">
– Miguel Campos