Ryan
Ryan

Reputation: 787

multiple links per row in mysql

I have a MySQL database in which each row represents an episode of a podcast. I would like to include show notes for each episode and therefore need to be able to extract multiple links per row via PHP.

What would be the best data field to achieve this? I'm thinking that including the links via a linked table may be the only way to do this, but if anybody knows a simpler way I'd love to hear about it.

Upvotes: 0

Views: 975

Answers (2)

bizzr3
bizzr3

Reputation: 1955

explode() Function :

You have to save your links for example with this structure : http:\\example.com\podcast01.mp3,http:\\example.com\podcast02.mp3,http:\\example.com\podcast03.mp3 in the database rows.

then when you want to extract them you can easily use explode() function with this way :

$links= $row['links']; // your links in row 
$links_array = explode("," , $links);// now you have an array that you can easily access to each block of it.

for example :

echo ($links_array[0]);// output : http:\\example.com\podcast01.mp3

good luck

Upvotes: 0

Richard
Richard

Reputation: 4415

I would definitely recommend using a new table (podcast_link) because the number of links per podcast is flexible. Adding a text field to the podcast table wouldn't be very efficient due to the parsing of the links when you want to display them. This will also allow you to e.g. count the number of links per podcast, so you can display "Show related links (4)" and you can add more fields to the links, so that you don't only display the links, but also a title for the link. Especially going forward you might want to add more information per link.

Upvotes: 1

Related Questions