Welcome, Guest. Please login or register.
Did you miss your activation email?
February 13, 2012, 01:36:53 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
149700 Posts in 21103 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: SQL query for updating field  (Read 342 times)
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« on: March 16, 2010, 02:40:51 PM »

I have a BIG site where I need to add an admin to all pages. I don't like to do that manually for each page, but I don't know how to create a SQL query. Can anyone give me a hand?

For all "pages" I want to change the "admin_groups" value from "1" to "2,1". How does that work?
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
pcwacht
AddOn Development
*
Offline Offline

Posts: 2814



WWW
« Reply #1 on: March 16, 2010, 04:20:30 PM »

NOT TESTED!!

Code:
$query = "UPDATE ".TABLE_PREFIX."pages SET  admin_groups = '2,1'";
$database->query($query);

This should set ALL pages to 2,1

you could allso do:
Code:
$query = "UPDATE ".TABLE_PREFIX."pages SET  admin_groups = '2,1' WHERE admin_groups = '1' ";
$database->query($query);


Look here for explanation : http://www.w3schools.com/php/php_mysql_update.asp

Have fun,
John
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #2 on: March 17, 2010, 01:46:24 AM »

Thanks very much John!
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #3 on: March 17, 2010, 10:48:05 PM »

Actually I needed just the SQL command to use in phpMyAdmin, but I figured that out from the above:

Code:
UPDATE pages SET admin_groups = '2,1' WHERE admin_groups = '1'

Worked like a charm!

It would be so nice to have a WB admin tool for setting access rights from the backend, for multiple pages at once... The current system is rather clumsy and inefficient. But these kind of SQL statements are a good substitute in the mean time.
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
pcwacht
AddOn Development
*
Offline Offline

Posts: 2814



WWW
« Reply #4 on: March 18, 2010, 08:32:52 AM »

Remember, an UPDATE without the WHERE clause will change every row in that table!

By Using a WHERE clause you can select one or more rows wich will be affected,
Example:
Code:
UPDATE pages SET admin_groups = '2,1' WHERE parent='6';
will change only those pages where the parent is page_id 6

tip
Copy the tabel yo wish to play on to another new table and experiment


John
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
Argos
Moderator
**
Offline Offline

Posts: 2084


WWW
« Reply #5 on: March 18, 2010, 11:40:05 AM »

Thanks, most useful info for SQL nitwits like me!  grin
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
pcwacht
AddOn Development
*
Offline Offline

Posts: 2814



WWW
« Reply #6 on: March 18, 2010, 12:52:27 PM »

I have learned it with a xampp install,
installed WB (I think the pre 2.6 version)
made some pages, newsitems etc

Fired up phpmyadmin and started to play with commands,
there are pretty descent tutorials out there in the g**gle-o-matic.

I still have troubles though doing really complex sql stuff like binding etc, but that is in most cases not even needed.

Have fun,
John
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!