skip to Main Content

I am trying to update my table column but I keep getting one value for all the rows, what am I doing wrong?

<?php

$count = 1;
while ( $count <= 30) {
    $fmle_img = "_src/img/profile/female/u$count.png";
    $db->query("UPDATE users SET image=:image WHERE (id > 31 AND id < 62)", array(':image'=>$fmle_img));
    $count ++;
}

// this keeps giving me _src/img/profile/female/30.png for all the rows between id 32 and id 61

?>

2

Answers


  1. You need to specify a single id in the WHERE clause of your sql statement.
    Try WHERE id = :id and pass as :id $count+30.

    Login or Signup to reply.
  2. You must vary the where condition for each image:

    <?php
    
    $count = 1;
    
    while ( $count <= 30) {
    
        $id = $count + 32;
        $fmle_img = "_src/img/profile/female/u$count.png";
        
        $db->query('UPDATE users SET image = :image WHERE id = :id', array(':image'=>$fmle_img, ':id' => $id));
        
        $count ++;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search