Updating a row...not all fields of it

I have a table which contains these fields

CREATE TABLE `services_list` (
  `serviceID` int(11) NOT NULL AUTO_INCREMENT,
  `price` decimal(5,2) DEFAULT NULL,
  `servicename` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
  `duration` smallint(5) unsigned DEFAULT NULL,
  `prices_visib` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`serviceID`)
) ENGINE=InnoDB AUTO_INCREMENT=457 DEFAULT CHARSET=latin1 COMMENT='it lists the possible services'

Take a look at this fiddle now:fiddle

The user has the option(after clicking edit) to update the values.
So he might update the service name only or the price or both…
Currently the query I am using cannot catch all these scenarios…

UPDATE services_list SET servicename=? WHERE serviceID IN ('.join(",", array_fill(0, $IDcount,"?")).')

the above is for updating the service only…the code inside it(join etc…) requires another explanation which for now I do not want to do…let us focus on the problem I describe above.

So I want to make a query that catches all these scenarios…the alternative multiple conditionals…something I want to avoid.

the SQL to update multiple columns is simply to update multiple columns, for example –

UPDATE services_list
   SET price = ?
     , servicename = ?
 WHERE ...

i believe you have a programming problem, not a database problem

So…I suppose I should post in the PHP forum?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.