index.php (not exact layout just snippits)
<!-- TRACK LIST -->
<a name="trackList">
<div id="trackList" class="container">
<?php
include("api/displayTracks.php");
?>
</div>
// AJAX
function update(actionUrl, outUrl, div){
if (actionUrl != "") {
$.ajax({
url: actionUrl,
cache: false,
success: function(html){
$.ajax({
url: outUrl,
cache: false,
success: function(html){
$(div).html(html);
},
});
},
});
} else {
$.ajax({
url: outUrl,
cache: false,
success: function(html){
$(div).html(html);
},
});
}
}
function updateTracks() {
update("", "api/displayTracks.php", "#trackList");
}
setInterval(updateTracks, 5000);
I build the function update to try fix this issue, previously i had AJAX calls in many functions but the same problem persisted.
The above code should update the #trackList
with new content every 5 seconds... But my issue is it isn't doing anything, i haven't much experience with AJAX, this is as far as my knowledge span goes.
I did however place a alert('test')
inside the update function and it successfully called every 5 seconds. So I've narrowed it down to the ajax.
displayTracks.php (the functions used in this are included at the top of index.php)
<?php
// display tracks
function displayLatestTracks($limit) {
$sql = sql("SELECT * FROM tracks WHERE (rank > 0) AND (isSet = 0) ORDER BY date DESC LIMIT ".$limit);
if (mysql_num_rows($sql) != 0) {
while ($row = mysql_fetch_assoc($sql)) {
if ($row['link'] != "") {
echo '<div style="background-color:rgb('.randColor().');" id="track-'.$row['id'].'" class="track">';
echo '<iframe width="100%" height="20" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='.$row['link'].'&color=b60000&inverse=true&auto_play=false&liking=true&show_user=true"></iframe>';
echo '</div>';
}
}
}
}
// display albums
function displayLatestAlbums($limit) {
$sql = sql("SELECT * FROM tracks WHERE (rank > 0) AND (isSet = 1) ORDER BY date DESC LIMIT ".$limit);
if (mysql_num_rows($sql) != 0) {
while ($row = mysql_fetch_assoc($sql)) {
if ($row['link'] != "") {
echo '<div style="background-color:rgb('.randColor().');" id="album-'.$row['id'].'" class="album">';
echo '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='.$row['link'].'&color=c50000&auto_play=false&hide_related=false&show_comments=true&show_user=true&liking=true&show_reposts=false"></iframe>';
echo '</div>';
}
}
}
}
echo '<p class="title">Track List</p>';
displayLatestAlbums(3);
displayLatestTracks(10);
?>
sql fucntion:
function sql($query) {
$sql = mysql_query(strip_tags($query));
if(!$sql) {
echo "Error processing query".mysql_error();
}
return $sql;
}