3
I’m in big trouble for me*
follows below as is being made select in the bank.
ini_set('display_errors', true);
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');
#
header('Content-Type: application/json');
header('Character-Encoding: utf-8');
define( 'MYSQL_HOST', 'localhost' );
define( 'MYSQL_USER', 'root' );
define( 'MYSQL_PASSWORD', '' );
define( 'MYSQL_DB_NAME', 'sistema' );
//$PDO = new PDO( 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD );
try
{
$PDO = new PDO( 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD );
}
catch ( PDOException $e )
{
echo 'Erro ao conectar com o MySQL: ' . $e->getMessage();
}
$sql = "SELECT tblinvoices.id, tblinvoices.clientid, tblinvoices.status, tblinvoices.duedate, tblclients.company, tblclients.website from tblinvoices INNER JOIN tblclients ON tblinvoices.clientid = tblclients.userid where tblclients.id = 1 ";
$result = $PDO->query( $sql );
$rows = $result->fetchAll(PDO::FETCH_OBJ);
$json_str = json_encode($rows, JSON_PRETTY_PRINT);
echo $json_str;
I have a return in JSON . that below .. I will display it to explain my situation;
[
{
"id": "1",
"clientid": "1",
"status": "2",
"duedate": "2017-09-05",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "8",
"clientid": "1",
"status": "2",
"duedate": "2017-10-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "15",
"clientid": "1",
"status": "2",
"duedate": "2017-11-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "16",
"clientid": "1",
"status": "2",
"duedate": "2017-11-03",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "17",
"clientid": "1",
"status": "2",
"duedate": "2017-11-03",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "24",
"clientid": "1",
"status": "2",
"duedate": "2017-12-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "31",
"clientid": "1",
"status": "2",
"duedate": "2018-01-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "40",
"clientid": "1",
"status": "2",
"duedate": "2018-02-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "47",
"clientid": "1",
"status": "2",
"duedate": "2018-03-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "60",
"clientid": "1",
"status": "2",
"duedate": "2018-04-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "61",
"clientid": "1",
"status": "4",
"duedate": "2018-05-06",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
},
{
"id": "68",
"clientid": "1",
"status": "4",
"duedate": "2018-05-03",
"company": "Cliente Exemplo",
"website": "clienteexemplo.com"
}
]
All right, up you go! What I want to do is take the status and make a condition; example : if the status is equal to 4 informo look at this late.. if the status is equal to 2 let me know that it is OK.
so I did like this basic: That CURL put there inside the customer code. so to give the message there;
$cr = curl_init();
curl_setopt($cr, CURLOPT_URL, "http://localhost/clientes/");
curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
//definindo uma variável para receber o conteúdo da página...
$retorno = curl_exec($cr);
//fechando-o para liberação do sistema.
curl_close($cr); //fechamos o recurso e liberamos o sistema...
$dados = json_decode($retorno, true);
if ($dados[0]['status'] == 4) {
echo "Olha Vencido";
}elseif ($dados[0] == 2) {
echo "Que Beleza você esta em dia.";
}else{
echo "tem alguma coisa errado.";
}
More as you can see there are several returns with equal status, so my problem begins, I want to get only the status(4) loser, if I make this change that’s coming from my bank, doing a Where status = 4 , I won’t be able to validate, whether it’s status(2) or not. Another issue is to pick by the id, plus I found another problem, if the id changes what will occur since the invoice is generated all month. I’m not getting anywhere on logic.
Where I take the status of the latest invoices, and make my condition;
Sorry about the long test. and I wanted to explain as much, if someone can give me a light.
So summarizing what you want: scan all the data and return the ones that have status 4 to make some logic following, correct?
– David Alves
What you want to do is not very clear in your explanation. But in a summarized way. You should only bring from the database what you need. You should not bring other values to delete them via PHP. Unless you need these values.
– alan