So let post my code first and then i'll explain my motivation and another issue that has presented itself that i'm trying to resolve.
?php
if (isset($_POST['submit'])) {
$mfr = $_POST['mfr'];
$type = $_POST['type'];
$desc = $_POST['description'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$last_id = 0;
$sql = "SELECT m_id FROM merchandise";
$result = mysqli_query($connection, $sql);
while($row = mysqli_fetch_assoc($result)) {
$last_id = $row["m_id"];
}
$next_id = $last_id+1;
$conc = number_format($next_id/100,2,'-','');
$query = "INSERT INTO merchandise (mfr,type,description,mer_sku,price,qty) ";
$query .="VALUES ('$mfr','$type','$desc','MR{$mfr}{$conc}','$price','$qty')";
$add_sku_query = mysqli_query($connection, $query);
confirmQuery($add_sku_query);
$alert = <<<DELIMETER
<div class='alert alert-warning alert-dismissible fade in' role='alert'>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Inventory Updated!</strong> <a href='inventory.php?view_all_inventory'>View All Inventory</a>
</div>
DELIMETER;
echo $alert;
}
?>
So first off let me point out that I did try to set this up using PDO but i'm not yet fully comprehending it so i'm sticking with mysqli. Which i know that how I have the code setup it leaves it vulnerable to SQL Injection.
So that aside, My motivation was to try and add items into a table sequentially. However, my code currently auto increments without regards to the $mfr variable which is ESSENTIAL. Each manufacturer has a unique value and so the auto increment would NEED to auto increment PER manufacturer instead of auto increment while disregarding the the manufacturer variable that is concatenated.
**CURRENT AUTO INCREMENT, [NOT WHAT I WHAT]**
MR500-01
MR600-02
MR700-03
MR500-04
MR600-05
MR700-06
**IDEAL AUTO INCREMENT, [WHAT I WANT]**
MR500-01
MR600-01
MR700-01
MR500-02
MR600-02
MR700-02
I hope I explained my thought. Anyways, this is my current status and I'm working towards creating the resolution that I NEEED.
Hope this was somewhat helpful to anyone or if someone has some helpful input that would be great and much appreciated. Thanks.
SET NEW.mer_sku = CONCAT(NEW.mer_sku, 'MR');at the end of the line?