Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

update sql column with php while loop

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

?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 ++;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading