ため 例
update post set img = 'your_image_path.png' where post_id='your_post_id';]
読むthisあなたがそれらを一つずつ更新することができますので、私は最初にすべてのポストIDを取得します。
ここにいくつかの擬似コードがあります。
// Get all post ids
// Change the database call to match your db library
$ids = $db->query("select id from posts");
$i = 0;
foreach (glob('../images/*.jpg') as $img) {
if (!array_key_exists($i, $ids)) {
// There's no more ids, so let's stop the loop
// and consider the script to be done.
break;
}
// Update one record with one image
$db->query("update posts set img = '{$img}' where id = " . $ids[$i]['id']);
// Increment the index so we will get the next
// post id during the next iteration.
$i++;
}
更新する行を指定するには、where句が必要になります。 SQL文は、すべての行を更新するように指示します。 –
レコードを更新する場合は、ID(またはそのレコードの他の一意の識別子)を持つ 'WHERE'節が必要です。それ以外の場合、データベースは更新するレコードを認識しません。 –
@MagnusEriksson、列全体、つまり各セルを異なる単一のimgパスで更新したい – bonaca