简体   繁体   English

在没有主键的情况下更新当前在MYSQL表上获取的数组PHP

[英]Update currently fetched array PHP on a MYSQL table without a primary key

I have a MySQl table with large number of columns without a primary key. 我有一个MySQl表,其中包含大量没有主键的列。 It is been imported via an external csv file. 它是通过外部csv文件导入的。

I have a php code which fetches cell values from the current row modifies them and have to replace/update the current row itself. 我有一个php代码,该代码从当前行获取单元格值会对其进行修改,并且必须替换/更新当前行本身。 I fetch the results simply by iterating through individual rows.. however as there is no primary key.. i am unable to modify the cell value. 我简单地通过遍历各个行来获取结果。但是,由于没有主键,所以无法修改单元格的值。

However, since there is no primary key, but php is fetching the current row, i just want to update the current row being fetched. 但是,由于没有主键,但是php正在获取当前行,因此我只想更新正在获取的当前行。 How can we grab the current row? 我们如何获取当前行?

Thank You. 谢谢。

If you're importing this from a csv file, I would recommend you to add a new "ID" column to the csv file. 如果要从csv文件导入此文件,建议您将新的“ ID”列添加到csv文件。 Set each value in that column to be a unique number (most likely the row number). 将该列中的每个值设置为唯一数字(很可能是行号)。 Then, when you import it into mysql, you'll have a unique row identifier to work with. 然后,将其导入mysql时,将具有唯一的行标识符。

如果您使用的是phpmyadmin,我建议您创建一个“ ID”字段以使您的任务更轻松

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM