Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/209588-update-table-on-click/
Share on other sites

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);
?>

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.

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.