0

I don't know how to make one of my columns (ListOfAvailableSeats) an array.I've tried but nothing works.Can you give me a hint, please? This is the latest version of the code:

ALTER TABLE `newconnectionmviescinema`.`allmovies` 
CHANGE COLUMN `LastUpdate` `LastUpdate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `Duration`,
CHANGE COLUMN `` `ListOfAvailableSeats` INT(60) NOT NULL ;

INSERT INTO `allmovies`.`ListOfAvailableSeats` VALUES ('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15');

1 Answer 1

1

Since MySql doesn't have an array type for storage, why not encode the array as JSON, and store the resulting string? Then decode it when you need to use the array from the table.

If I was doing this in php, I'd use something along the lines of:

<?php
  $values = array();
  array_push($values, 1);
  array_push($values, 2);
  array_push($values, 3);
  array_push($values, "chicken");
  $toStore = json_encode($values);

  //Store $toStore as you would any other large string.
  //When you need it use it like this:

  $freeSeats = "";
  $data = json_decode($jsonFromDatabase); //If you had an associative array like $data['name'], then you would add json_decode($jsonFromDatabase, true);
  foreach($data as $seat){
    $freeSeats .= $seat . ", ";
  }

  echo "The free seats are " . $freeSeats;
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.