1
I have a logic problem, actually and I can’t evolve what I need to do with a code. Follows description of the problem:
Problem:
I have a list of products and need to inform on a screen if the product is on Promotion or not.
That’s what I chose to do checkbox
where the value 1 is Allow and value 0 is Not Allow (unchecked). In the database, in the table Products I have a column called isPromotion who gets those zero or one.
The problem is that I need to reference in which product that value will be assigned, so I put together each product, a input
of the kind hidden
containing the value of the id of each product, something common when assembling these screens.
<input type="hidden" name="idProduto[]" value="<?= $Produto->id; ?>">
Now, suppose I want to mark 5 products as Promotion, i will mark the checkbox of each product and with it add to an array of data. So each product has a input
of the kind checkbox
whose name
is declared as an array, see below:
<input class="form-check-input" name="promotion[]" type="checkbox" <?= $Produto->isPromotion != 1 ? 'checked' : ''; ?> value="<?= $Produto->isPromotion ; ?>">
Now we have 2 array: one with the Promotion values and the other with the corresponding product IDS.
Here comes my doubts and problems with logic: The IDS array sends all product IDS because it is already set in input, so it is obvious that the array will return all IDS, and the Promotion Array of values returns True or False.
How can I send these values (Allow / Not allow) to the database, EACH WHICH IN YOUR DATABASE RECORD? I don’t have much code, and I’ve tried a few tricks to make it work.
I accept any idea, and please avoid posting comments on other questions. I know how to select various checkbox values and send them to the database. My problem is how I make so that each product that has its own checkbox and its value is sent to the Database in its respective record.
I do not know if I was very clear, but I am available if you need more information;
Thank you to all who can help! Thank you :)_
Take a look at the property Htmlelement.dataset. This property allows you to link arbitrary data to HTML elements. It can be used to link pids, prices, quantities, promotions,...
– Augusto Vasques