So I have 2 variable for storing the selected time of the user ('time_to' and 'time_from) with these sample data('7:30','8:00') How can I save these two into 1 column('c_time') so it would look like this('7:30-8:00')?
CodePudding user response:
if i understand you correctly, you can create a column of string (varchar)
type. and then create the data for your column like this :
$time_to = '7:30';
$time_from= '8:00';
$colValueToBeStored = "(".$time_to."-".$time_from.")";
then just put $colValueToBeStored
inside your column.
CodePudding user response:
define your c_time
column type as JSON, that way you can store multiple values, as it will be easier to retrieve as well. Like,
...
$cTime['time_to'] = "7:30";
$cTime['time_from'] = "8:00";
$cTimeJson = json_encode($cTime);
// save to db
...