Hello

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

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);
}

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.

Totally put too much thought into that one. @Shark_1 is correct!

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)).")";

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']."'");
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.