Storing strings in the database mimicking a matrix


What is the best way to store a ton of links into 1 db column but for only 1 id and making it like an array?, I cant quite get this to work as I need them to be categorized in a way.



ID | links

1 | -Links Here-

2 | -Completely Seperate Unrelated Links-


So, I need the 'links' to be seperated and categorized. I tried doing explode() which puts it into an array but you just cant organise it that way, I tried making seperators different e.g, ~1~, ~2~, ~3~ but I just couldnt get it to categorize properly. Do note that 100's of links will be going into this one column which probably sounds like a bad thing to do but id rather this way then 50-100 ish columns for simply storing links.

Tried Code:

if($rdl['links'] != '') { $s1dl = explode("~S1~", $links); }

substr(strstr($s3dl, 'http'), strlen('http'));

echo $s3dl[0];
echo $s3dl[1];
echo $s3dl[2];

UPDATE: Basically I need a way to have a user inputted field, You put the link in it, then send it to the DB in an array or something categorizable but an array would be best.

So I made a Season and Link field. I have got this:

$linkadd = $db2->prepare("INSERT INTO dl (link) VALUES (:link) WHERE imdbid LIKE :id");

Do note, If I use encode or Serialize how am I meant to "Append" the user entered link into that serialized array that is ready to be unserialized?

Where do I go from here?

Would something like this work?:

$currentlinks = unserialize($rdl['links']);
$currentlinks[] = $_POST['link'];
$newlinks = serialize($rdl['links']);

$linkadd->execute(array(':link' => $newlinks));

If you need to have them all into a single field, you could put them all into an array, encode it, and store the resulting string in the database. You could choose e.g. either of these:

$valueForDatabase = json_encode($my_links);
// or
$valueForDatabase = serialize($my_links);

Then, when you get the field from the database, you use the corresponding decoding function:

$my_links = json_decode($valueFromDatabase);
// or
$my_links = unserialize($my_links);