Jump to content

How can i search in a table specific field value and replace it with another


Recommended Posts

Hello guys, please need to search in a table and find specific values in a field and replace it with a value in another field of the same table.

 

certain i will use such

mysql_fetch_array($result)

Help needed please

 

Thanks in advance

Can you provide some more details? Will the value be replaced with a value from another field in the same record? From a different record?

Assuming you mean the value is in the same record, you can do it all in a single query like so:

UPDATE `table` SET `field1` = `field2` WHERE (some condition exists . . . )

 

You may want to copy your table and test it on the copied data to verify it does what you want it to do before using it on production data.

Thanks Pikachu2000 for your reply, but here i have to walk through the whole records and then find  the values that will be changed and replace it from the other field of the same table, like for example col1  values to be replaced by values from col2 on certain condition and through the whole records, thus i need to run through foreach or some thing like that.

hoverinc, the SQL update statement will run through the entire table and update all records that match your where condition.  That's how it works, always.  Pikachu gave you the code you need to use.  To do it the way that you are thinking about is way too complicated.  Look into the SQL more.

Dear guys Infact we are transfering contents of website to another, so we have 3 tables, one table that have articles in (field X) these article related to images in another table that have 2 fields (ID OF ARTICLE) & (ID OF IMAGE) and the third table contains fields of (IMAGE ID) & (IMAGE NAME) this all were in the previous style of the website, means there are 3 tables, but now we are transferring to JOOMLA, so in joomla we have transferred all articles of the first table that contains the articles of 6000 records, now WE NEED TO ATTACH EVERY IMAGE TO ITS ARTICLE in the first table by adding in the text the <IMG> tags so can read the path.  AND IN REALITY I THINK WE HAVE TO COMPARE ID OF IMAGE TO IT'S PROPER ARTICLE SOMETHING LIKE THAT,  I NEED YOUR COLLABORATION OF DEMONSTRATING THIS PLEASE OR IDEADS THAT SIMPLIFIES THIS TYPE OFWORK... THANKS ;D:D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.