update problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

update problem

Post 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!
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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");
}
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

sebs wrote:' is giving some problems too.
mysql_real_escape_string()
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

Don't mind this thread.I solved the problem!It took me almoust a day of hard work but I solved it!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

I tryed that and believe it's not working for a very big database.Thanks!
Post Reply