FAQ |
Kalender |
![]() |
#1 | ||
|
|||
Bara ett inlägg till!
|
Denna uppdateras inte själv.. Hur fixar man så den uppdateras själv?
Tacksam för hjälp.. Php koden Kod:
<?php //Sam Broadcaster - AJAX Module - Send Artist/Title/Duration and Seconds remaining to getXMLHTTPRequest //Written, cobbled together by wilksy101. This code contain code sourced from the support forums and stuff written myself // Change to your database user name $username="xxxx"; //Change to your database password $password="xxxxx"; // Change to your database name $database="xxxx"; // Connect to the database mysql_connect('ipaddress',$username,$password); // Handle an error @mysql_select_db($database) or die( "Unable to select database"); // Build Sql that returns the data needed - change this as required. $sql = "SELECT songlist.*, historylist.listeners as listeners, historylist.requestID as requestID, historylist.date_played as starttime FROM historylist,songlist WHERE (historylist.songID = songlist.ID) AND (songlist.songtype='S' OR songlist.songtype='C' OR songlist.songtype='N') ORDER BY historylist.date_played DESC LIMIT 1"; // Store results in result object $result = mysql_query($sql); //store values in vars for calculation for array creation $dt_played = mysql_result($result,$i,'date_played'); $dt_duration = mysql_result($result,$i,'duration'); $title= mysql_result($result,$i,'title'); $artist= mysql_result($result,$i,'artist'); $picture= mysql_result($result,$i,'picture'); $starttime = strtotime($dt_played); $curtime = time(); $timeleft = $starttime+round($dt_duration/1000)-$curtime; $secsRemain = (round($dt_duration / 1000)-($curtime-$starttime)); //build array to return via getXMLHTTPRequest object - you can include more vars but remeber to handle them //correcty in the useHttpResponse function $Aj_array = $dt_duration . '|' . $secsRemain . '|' . $title . '|' . $artist .'|' . $picture; //we are using the text response object - which i think is easier for small data return //just echo the array - not so much AJAX rather AJA ?? echo $Aj_array ?> Kod:
<script language="JavaScript"> var http = getXMLHTTPRequest(); var counter; function getXMLHTTPRequest() { try { req = new XMLHttpRequest(); } catch(err1) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err3) { req = false; } } } return req; } function getServerText() { var myurl = 'http://www.yourwebsite.com/aj_TimeRemain.php'; / enter the full path to the aj_TimeRemain.php path myRand = parseInt(Math.random()*999999999999999); var modurl = myurl+"?rand="+myRand; http.open("GET", modurl, true); http.onreadystatechange = useHttpResponse; http.send(null); } function useHttpResponse() { if (http.readyState == 4) { if(http.status == 200) { // parse data returned from aj_TimeRemain.php var aj_results = http.responseText.split("|"); var aj_duration = aj_results[0]; var aj_secsremaining = aj_results[1]; var aj_title = aj_results[2]; var aj_artist = aj_results[3]; // update title and artist divs document.getElementById('title').innerHTML = aj_title; document.getElementById('artist').innerHTML = aj_artist; //set seconds remaining to the countdown car - adding '-0' to convert to number countDownInterval = aj_secsremaining - 0; countDownTime = countDownInterval + 1; countDown() } } else { //document. getElementById('actual').innerHTML = ""; } } function countDown() { countDownTime--; if (countDownTime == 0) { countDownTime = countDownInterval; getServerText() } else if (countDownTime < 0) countDownTime = 30; if (document.all) document.all.countDownText.innerText = secsToMins(countDownTime); else if (document.getElementById) document.getElementById("countDownText").innerHTML = secsToMins(countDownTime); stopCountDown(); counter = setTimeout("countDown()", 1000); } function secsToMins(theValue) { var theMin = Math.floor(theValue / 60); var theSec = (theValue % 60); if (theSec < 10) theSec = "0" + theSec; return(theMin + ":" + theSec); } function stopCountDown() { clearTimeout(counter) } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #999999; } --> </style></head> <body onLoad="getServerText()"> <div id="title"></div> <div id="artist"></div> <div id="countDownText">loading</div> </body> </html> |
||
![]() |
![]() |
|
|