1
I’m making an appointment at Mysql to return the quantity of orders that were not delivered.
To see what was delivered I do:
$result = mysql_query("SELECT operacional FROM `pedidos` WHERE `status` = 'ENTREGA REALIZADA'");
However, there are some requests that status is: DELIVERY HELD ON 20/10/2017 or even DELIVERY HELD ON 20/11/2017 - that is, the dates vary.
And besides, I need to take the ones that were not delivered. How can I receive only the items that do not have this text of "DELIVERY PERFORMED"? Because this space never goes blank, there will always be something like OUTING or UNIT ENTRY, among others...
There is something like:
$result = mysql_query("SELECT operacional FROM `pedidos` WHERE `status` != 'ENTREGA REALIZADA'");
SQL is still on my list for in-depth studies, but doing something like
status not like "ENTREGA REALIZADA%
functionary?– Woss
Guys, I did it like this: I created a new column in DB, "active" being it of type INT, if it is 0 php reads and updates, if it is 1 it jumps... it worked!
– Pedro Daher
Peter, feel free to draft an answer and post it here as a solution. It is not bad conduct to do this, in fact, it is even well supported since it well done. Read more on Answer your own question.
– Woss
The problem with the original code is that a violation of the 1NF. You are using two distinct data in the same column. The best option would be to have
status
anddata
, That way there would be no problem, each one serves for a thing and only saves one information. As also stated by @Alisson Acioli you can use numeric fields (TINYINT) to decrease the space used and make Indexes more efficient, another option (maybe not the best) is to use the ENUM.– Inkeliz
Remember that the mysql_* functions are obsolete and have been removed in php 7. It is recommended to use mysqli_* or PDO
– Marcos Xavier
Thank you guys, you helped me a lot, the fact that I need to make all this complication is because the information comes to my bank through a webservice, only after that I can manipulate... All helped me a lot! Strong hug!
– Pedro Daher