liamloveslearning Posted August 2, 2010 Share Posted August 2, 2010 Hi all, I'm just wondering what the best solution to my current problem would be. Ive created a website where users can upload photos to a database, the photos are then shown in the admin section as a list. My DB structure is as such.. PHOTO SRC THEME 1.jpg images/1.jpg 1 2.jpg images/2.jpg 0 3.jpg images/3.jpg 0 4.jpg images/4.jpg 1 This is then reflected in the admin page, I need a button which will alter all photo's with the theme '1' and change them to '0', like a reconcile button, is this possible? How would you go about it? Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/209588-update-table-on-click/ Share on other sites More sharing options...
Skewled Posted August 2, 2010 Share Posted August 2, 2010 It's possible.. hope this helps. I'm using a foreach loop to continue the operation on every theme where the field value is a 1. This should effectively change them all to 0. <?php // Do your database connection here $dbc = mysqli_connect( ); $changeto = 0; $fields = Array('theme'); foreach ($fields as $fld) { $query = "UPDATE (database name) SET $fld=$changeto WHERE theme = 1"; mysqli_query($dbc, $query) or die ("Cannot execute: " . mysql_error()); } mysqli_close($dbc); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209588-update-table-on-click/#findComment-1094196 Share on other sites More sharing options...
liamloveslearning Posted August 2, 2010 Author Share Posted August 2, 2010 brilliant, ill have a go, thanks kadeous Quote Link to comment https://forums.phpfreaks.com/topic/209588-update-table-on-click/#findComment-1094202 Share on other sites More sharing options...
jcbones Posted August 2, 2010 Share Posted August 2, 2010 I'm using a foreach loop to continue the operation on every theme where the field value is a 1. Just a note, Being that you are setting the value of a field where theme = 1, then all fields with theme equaling 1 will be updated. Which means, that on your first time through your loop, then all of the rows that have 'theme = 1', will be changed to 'theme = 0'. If you need it run by individual rows, you will need it to check against the PHOTO. Ideally you would want to check against an individual ID field, but it appears you don't have that in your table. Quote Link to comment https://forums.phpfreaks.com/topic/209588-update-table-on-click/#findComment-1094359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.