menu

Questions & Answers

How to Add Multiple Data to MySQL Database per ID?

Forgive me if its confusing, I'll try to elaborate it much clearer.

I have this SQL Data on my Database. Id like to add data per IDCode. whether Horizontally like this or vertically like this.

What's the most possible way of adding a data per unique id, and how can I maintain it so that the data that is stored inside can all be called once I call the IDCode.

Im new on Doing SQL Database.

BTW

mysqli_query($conn, "INSERT INTO partners VALUES('', '$ptname', '$issuedate', '$amount')");

This my CODE. Dont know if it helps.

foreach($reader as $key => $row){
    $ptname = $row[0];
    $issuedate = $row[1];
    $amount = $row[2];
                    
mysqli_query($conn, "INSERT INTO partners VALUES('', '$ptname', '$issuedate', '$amount')");
                }
Comments:
2023-01-17 00:48:42
Careful, that code looks wide open to SQL injection attacks. A fatal and dangerous security flaw. There is really is no excuse to be writing such code any more; learn from the mistakes of those in the decades past and parametrise your code.
2023-01-17 00:48:42
"Horizontally" makes rather little sense, because you would have to add columns to your database all the time. You should do it "vertical", add a new record for each combination of IDCode and data. You can not leave the IDCode column empty though, that makes no sense. Do not confuse the actual data, and a specific way of displaying it.
2023-01-17 00:48:42
Thank you for the Information. I thought it would be possible but if its not. Thats okay as well. But is there any alternative in which I can call all of the value that is associated with IDCode or such
Answers(0) :