I am currently working on a media playlist site, two separate pages for audio and video.
This is playlist.php that is dynamically loaded into the page using javascript:
$sql = new mysqli('localhost', 'root', '', 'bunnytwitchy');
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit;
}
$query = "SELECT * FROM `playlist` WHERE `playlistname`='playlist 1'";
$result = $sql->query($query);
if (!$result) {
printf("Query failed: %s
", $mysqli->error);
exit;
}
while($row = $result->fetch_row()) {
$rows[]=$row;
}
foreach($rows as $row) {
$mediaid = $row[1];
$query = "SELECT * FROM `media` WHERE `id`='$mediaid'";
$result = $sql->query($query);
if (!$result) {
printf("Query failed: %s
", $mysqli->error);
exit;
}
while($playlistlist = $result->fetch_row()) {
$playlist[]= $playlistlist;
print_r($playlist);
}
}
The reason I have select * from both tables, I'm collecting information from both the playlist table and the media table.
While getting both tables information, im trying to compare the playlist song id's with the media id's so it knows which songs and info go in the playlist.
My DB structure is:
db: bunnytwitchy
tables: playlist, media
playlist: playlistid, mediaid, playlistname
media: id, type, band, song, album, path
In the above code, playlistid is compared with the media id's to know which songs are in the playlist. Media type is to determine video / music. Path is the media file location.
Right now my array of the media information is working great, other than it displays the first matched id twice:
Array
(
[0] => Array
(
[0] => 3
[1] => video
[2] => band2
[3] => song2
[4] => album1
[5] => video/3.mp4
)
)
Array
(
[0] => Array
(
[0] => 3
[1] => video
[2] => band2
[3] => song2
[4] => album1
[5] => video/3.mp4
)
[1] => Array
(
[0] => 1
[1] => video
[2] => bandname
[3] => songname
[4] => album
[5] => video/2.mp4
)
)
The reason id 2 is missing is because it's a music file rather than video.
I was hoping someone out there could help me figure out why it's displaying the first matched id twice in the array and possibly how I can fix it
All help is appreciated! Thanks