0
I have a table called label, with nameTag varchar and Quant int 11.
When I insert in the label table, I have to increase the total quantity registered in the bank +1. But I don’t know how to do this without having to do another query and then add through php. You can do this without the whole process of another query with PHP?
$querysql = $con->prepare("INSERT INTO rótulo(nomeTag, quant) VALUES(?,?)");
$querysql->bindValue(1, $nomeTag);
$querysql->bindValue(2, "SELECT quant+1 FROM rótulo"); // nessa linha qe eu ñ sei
$querysql->execute();
Can you do something like that? Can someone help me?
it is necessary to first select the table and then do Insert
– Victor
Is there no other way? Similar to the example I asked?
– user98519
I’m saying I think it’s more viable, but you can expect someone more experienced, but I’ve never used it and I haven’t seen it like this
– Victor
I believe that when you enter the record you already have an extra record, that is, +1, in your database. see if your database has id <auto increment>
– Victor
insert select
has another syntax.– Jefferson Quesado
It is to make a counter of how many posts you have with a certain label, and one can be auto-increment
– user98519
Do you really need to save that amount? Don’t you want to make one
count()
when recover this information? this situation seems the same as recording age as aint
there every year you increase :)– rray
This nametag will be repeated anyway?
– adventistaam
I would use a TRIGGER AFTER UPDATE https://www.techonthenet.com/mysql/triggers/after_update.php
– SandroMarques
It does not make sense what you are trying to do, or I did not understand your question, because it is only you create a field with primary key and auto_increment that will do this for you automatically, Ref: https://dev.mysql.com/doc/refman/5.7/en/example-auto-increment.html
– arllondias