0

Hello

I have 5000 data how can i update one time
dbquery("UPDATE ".CATEGORY_TABLE." SET name='".cleanString($data['title'])."'");

4
Contributors
5
Replies
30
Views
2 Years
Discussion Span
Last Post by afaaro
0

Something like this.

$connection = mysqli_connect("localhost", "my_user", "my_password", "world");

$sql = "UPDATE tablename SET 'table_record' = 'new_value'";

for($i=0, $i<4999;$i++)
{
    mysqi_query($connection, $sql);
}
0

If you like to edit the field with same value of all 5000 records simply use

$sql = "UPDATE tablename SET table_record = 'new_value'";

No need of for or do loop.

Secondly, if you like to edit the feild with seperate value use a where clause in your SQL Statement to match the records.

$sql = "UPDATE tablename SET table_record = 'new_value' Where Field_Name = 'Match_Value'";

No need of any type of loop.
Suppose, it should help you.

0

Update large number of records may cause slow performance. I suggest to use bulk update. and hopefully these may help you soon if you need it.

update multiple records in 1 query

UPDATE mytable SET title = CASE
WHEN id = 1 THEN 'I\'m alive';
WHEN id = 2 THEN 'I\'m dead';
ELSE title
END;

you can play with array in this update.

example:

    $idval = array('1'=>'I\'m alive','2'=>'I\'m dead');
    $sql = " UPDATE mytable SET title = CASE ";
    foreach($idval as $id=>$val){
        $sql .= " WHEN '$id' THEN '$val' \n";
    }
    $sql .= " END WHERE id in (".implode(',',array_keys($idval)).")";
0

Thank you everyone for your support I came up with this and it's working

if($result = dbquery("SELECT title,name FROM ".CATEGORY_TABLE)){
    while($row = dbarray($result)){
        dbquery("UPDATE ".CATEGORY_TABLE." SET name='".cleanString($row['title'])."' WHERE title='".$row['title']."'");
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.