Skip to main content
Known Participant
November 2, 2010
Answered

update or delete all records

  • November 2, 2010
  • 1 reply
  • 804 views

Hi everyone!

Im making a site with PHP, and wonder if i can achieve this:

First: Let's say that the db has 30 records in a table, and i want to change a particular data in all the records. How can i do this?

Second: In the same way, how can i delete all the records of that table?

For example:

table 'example'

cols id, title, content, description

If i want to "reset"(change it's value to none, for example) the 'description' value in all the records of that table, how can i do that?

And second: how can i truncate the whole table? (TRUNCATE = dump all the data inside the table, right?)

All of this from php, not from phpmyadmin lol!

Thanks in advance

Cheers!

This topic has been closed for replies.
Correct answer

Like I said in the previous reply: use the UPDATE and DELETE MySQL commands. Look 'em up for examples. There's plenty of examples out there that will do what you want. Basic examples are:

UPDATE table_name SET column_name=something, column_name_2=sometingelse

or

DELETE FROM table_name where field = something.

1 reply

November 2, 2010

You don't need php to do this, it's technically MySQL that does this.

use UPDATE,and DELETE functions in mysql. Look 'em up for examples. If you want to dump a table then use DUMP.

javissssAuthor
Known Participant
November 2, 2010

Thanks for the reply IPHP

I know this actions are maded by mysql. But the site has an administrator section, and i wish to add that functionality IN the administrator page. For example, if i want to update a single record, i can do it trough the update form, build it with the prebuilded scripts in DW. But if i want to update ALL the records, what are the tweaks i need to make in that script to achieve this goal?

Like a link: when the user clic that link, the page linked take this action:

1º: Turn all the values from column 'description' in db 'example' to ' '

2º: After that, go to (some page)

Same mode to truncate the data in the table, not the table itself

Cheers!

Correct answer
November 2, 2010

Like I said in the previous reply: use the UPDATE and DELETE MySQL commands. Look 'em up for examples. There's plenty of examples out there that will do what you want. Basic examples are:

UPDATE table_name SET column_name=something, column_name_2=sometingelse

or

DELETE FROM table_name where field = something.