Page 1 of 1

update problem

Posted: Thu Oct 27, 2005 5:45 am
by sebs
I have a table with some categories and a number coresponding with that category.
I also have a big database and I want to change the category name with the number coresponding with that category.I haven't managed to do that.Any ideas?
My program looks like:

Code: Select all

$sqlquery="SELECT ID,micro from firme_micro";
$result=mysql_query($sqlquery);
while($data=mysql_fetch_array($result))
{
$sql="UPDATE firme_save SET micro='$data[0]' where firme_save.micro='$data[1]' ";
$resu=mysql_query($sql)or die("not enter");
}
The problem is this is not working,or it's working only for some categories.
I also have some categories like this ski' & snow(for example). ' is giving some problems too.Thanks!

Posted: Thu Oct 27, 2005 8:31 am
by hawleyjr
Have you tried to debug?

Code: Select all

$sqlquery="SELECT ID,micro from firme_micro";
$result=mysql_query($sqlquery);
while($data=mysql_fetch_array($result))
{

$sql="UPDATE firme_save SET micro='$data[0]' where firme_save.micro='$data[1]' ";

echo '<br /> ' . $sql;

$resu=mysql_query($sql)or die("not enter");
}

Posted: Thu Oct 27, 2005 8:56 am
by n00b Saibot
sebs wrote:' is giving some problems too.
mysql_real_escape_string()

Posted: Fri Oct 28, 2005 2:04 am
by sebs
Don't mind this thread.I solved the problem!It took me almoust a day of hard work but I solved it!

Posted: Fri Oct 28, 2005 4:05 am
by timvw
If i'm not mistaken, the following query should do it all at once...

Code: Select all

UPDATE firme_save, firme_micro
SET firme_save.micro=firme_micro.ID
WHERE firme_save.micro=firme_micro.micro

Posted: Fri Oct 28, 2005 4:57 am
by sebs
I tryed that and believe it's not working for a very big database.Thanks!