I have two columns:
stock = string "yes" or "no"
And the other column with amount:
stock_c = value 0 to 100 (limit 100)
Use utf8_general_ci collation and the columns are in the products
tableWhat I want to achieve is:
$stock_c = $_POST['cantidad']; // 0 a 100
mysqli_query($cnx, "UPDATE productos SET stock_c = $stock_c");
$query = "SELECT * FROM productos WHERE productos.stock_c = $stock_c";
mysqli_query($cnx,$query);
// en este caso verificariamos si stock es = o mayor a 1.
if($stock_c => 1) {
mysqli_query($cnx,"UPDATE productos SET stock='si' WHERE id_producto=$id_producto");
}
else {
mysqli_query($cnx,"UPDATE productos SET stock='no' WHERE id_producto=$id_producto");
}
// si lo es, actualiza stock = "Si" caso contrario ="No"
Surely something is wrong in the code, I just structured it while thinking the question to put as a supposed example or "almost total" as a guide for the solution.
In summary:
If $stock_c = 0
| Update or Enter in $stock = "No";
If $stock_c =>1
| Update or Enter in $stock = "Si";
Something to add:
The user or client will have a% co_of numeric% for the amount to add.
Here you should have a limit set to $ stock_c
And if <input>
deactivate the $stock_c = 0
Code that at the moment I use to reflect $ stock
<div class="stock"><p>Stock:
<?php
if (strcasecmp($columnas['stock'], 'si') === 0) {
echo '<span class="product-stock st-si">' .$columnas['stock'] ."</span>";
}
else{
echo '<span class="product-stock st-no">' .$columnas['stock'] ."</span>";
}
?></p> </div>
This code was obtained by asking: Check stock and add classes Thanks to @DevJoel .