I have a table with 1 column that stores the ID auto_increment and with that instruction:
$query = "SELECT first_data, second_data, third_data
FROM table_data
WHERE condition = 'value_condition'";
$result = mysql_query($query) or die(mysql_error());
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
while($row = mysql_fetch_assoc($result)) {
$valueone = $row['first_data'];
$valuetwo = $row['second_data'];
$valuethree = $row['third_data'];
$queryTwo = "INSERT INTO historial_ventas (reg1, reg2, reg3)
VALUES('$ivalueone','$valuetwo','$valuethree')";
$resultTwol = mysql_query($queryTwo) or die(mysql_error());
}
} else {
return false;
}
Information is stored as follows:
ID(auto_increment) reg1 reg2 reg3
______________________________________________
1 value1 value2 value3
2 value1 value2 value3
3 value1 value2 value3
4 value1 value2 value3
But I want the records maintained in the while loop, stored with the same ID as in a purchase online, ie you save the products and their features but with the same ID to buy, as this way:
ID(auto_increment) reg1 reg2 reg3
______________________________________________
1 value1 value2 value3
1 value1 value2 value3
1 value1 value2 value3
1 value1 value2 value3
The normalized way is to use a joint table like this:
Both PurchaseId
and ItemId
are set to auto-increment. The purpose of a Primary Key is to uniquely identify each row.
Read up on Database Normalization on how you can design your database to be effective.