Query MySql with PHP

1

I am making a query in MySql to return the quantity of requests that have not been delivered.

To see the ones that have been delivered I do:

$result = mysql_query("SELECT operacional FROM 'pedidos' WHERE 'status' = 'ENTREGA REALIZADA'");

However, there are some requests that the status is: DELIVERY HELD ON 10/20/2017 or even DELIVERY HELD ON 11/20/2017 - that is, the dates vary.

And besides, I need to pick up the ones that have not been delivered. How can I make to receive only those items that do not have this "DELIVERY" text? For this space is never left blank, there will always be something like EXIT LIST or ENTRY INTO UNITY , among others ...

There's something like:

$result = mysql_query("SELECT operacional FROM 'pedidos' WHERE 'status' != 'ENTREGA REALIZADA'");
    
asked by anonymous 05.05.2017 / 16:26

2 answers

0

Thanks to everyone! I confess that they solved my problem and I learned a function that I did not yet know.

For this problem I decided to create an "Active" table to know if the request enters the operation (which is to receive the data update):

Ifitis0itreceivestheupdatewhentheroutinehappens,if1itskipsthisrequest.

IftherequestthatreceivedtheinformationhasStatus->DELIVERYmadeactivechangesto1:

I think it's safer this way! A big hug and thank you for the information, it was of great importance!

    
05.05.2017 / 20:51
4

Friend a tip I give to you is never to use text in fields of type status . Instead, you could easily solve this by using the status field as INT . Doing something like this:

0 = Não Realizado
1 = Entrega Realizada
2 = Saída para Lista
3 = Entrada na únidade

And in the date delivery issue, you could create another field in the table called (for example) data_status and whenever the status is 1 you update that column and put the date.

If you want, you could also create a separate table with only status for query, something with the structure like this:

id
id_status
nome_status

So you can avoid future problems.

With your above case

I could test the following command and see which fits best:

$result = mysql_query("SELECT operacional FROM 'pedidos' WHERE 'status' LIKE '%ENTREGA REALIZADA'");

$result = mysql_query("SELECT operacional FROM 'pedidos' WHERE 'status' LIKE '%ENTREGA REALIZADA%'"); //Talvez dê problemas no futuro caso tenha frases muito parecida no campo status

$result = mysql_query("SELECT operacional FROM 'pedidos' WHERE 'status' LIKE 'ENTREGA REALIZADA%'");

But do as I said at the beginning of the post, you'd better avoid future headaches and trouble.

Remembering how Anderson Carlos Woss mentioned, use the mysqli_ function because all mysql _ are obsolete in the new versions of PHP.

    
05.05.2017 / 17:37