How do I change everything to a single php value

Asked

Viewed 55 times

4

My question is this::

In a table, I have a column designated nomecliente.

In this table I have several records, however the column nomecliente of the records are different from each other.

How could I do a mysql_query UPDATE, to select all records from the column and put a single value to all in that same column?

  • you want to leave the client name equal for all?

  • Exactly, all with the same name.

  • 1

    denied the question? : The

  • 1

    That question is in the closing line because it’s supposedly not clear enough. It is clear to me, and if rray (or someone else) had not already given a good answer, I would respond promptly. So, I’ll mark it "Leave it open".

1 answer

8


To set a value for all records of one or more columns only omit the WHERE no update. Some databases (like Mysql) have a 'lock' against an update/delete without WHERE because usually this is seen as an error, in doubt generates a backup table to have the data before the change.

UPDATE cliente SET nomecliente = 'sera mesmo'

Let’s say the table has the following records

id|nome
1 |fulano
2 |ciclano
3 |beltrano

After that instruction UPDATE cliente SET nome = 'mario' the table will be as follows:

id|nome
1 |mario
2 |mario
3 |mario
  • In 8 minutes I’ll accept the answer.

  • 1

    An alternative to this lock quoted by @rray is to use WHERE 1=1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.