Jump to content

[SOLVED] what is wrong with this piece of code? php/mysql simple echo / update


johnwayne77

Recommended Posts

what is wrong with this code?

 

$query = "SELECT * from cp_products2";
$doq = mysql_query($query);
while ($row = mysql_fetch_assoc($doq)) {

$catid = $row['cat_id'];
$newcatid = $catid . "mns";
$query2 = "UPDATE cp_products2 SET cat_id = '$newcatid' WHERE cat_id = '$catid'";
$doq2 = mysql_query($query2);
echo "categorie veche: " . $catid . " | Categorie noua: " . $newcatid . "<br>";

}

 

it echoes correctly but it doesn't update the fields..

 

any ideas?

Try this

 

<?php

$query = "SELECT * from cp_products2";
$doq = mysql_query($query);

$start = 0;

while ($row = mysql_fetch_assoc($doq)) {
   
   $catid = $row['cat_id'];
   $newcatid = $catid . "mns";
   $query2[$start] = "UPDATE cp_products2 SET cat_id = '$newcatid' WHERE cat_id = '$catid'";
   mysql_query($query2[$start]);
   echo "categorie veche: " . $catid . " | Categorie noua: " . $newcatid . "<br>";
   
  $start++;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.