I have a big problem for me *
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. this one 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"
}
]
Beauty up there! What I want to do and get status and make a condition; example: if the status is equal to 4 informo look this delayed .. if the status is equal to 2, that is OK.
So I did so basic : This CURL places it inside the client 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.";
}
As you can see, there are several returns with the same status, so my problem starts, I want to get only those statuses (4), if I make this change from my bank, doing a where status = 4, I will not be able to validate, if it is status status (2) or not. Another issue is to get the id, plus I found another problem if the ID changes what will occur since the invoice is generated all month. I can not get into a logic.
Where I get the status of the last invoices, and I make my condition;
Sorry for the long test. and that I wanted to explain the maximum, if anyone can give me a light.