Obecnie działa wszystko ok, odświeża mi wynik co pół sekundy ale wyświetla tylko jeden wynik a chcę wyświetlać 5 ostatnich.
Kod:
Zapytanie do bazy:
Klient:
<!--------------------------------------------------------------------------------------------- by Trystan Lea : openenergymonitor.org : GNU GPL I recommend going to <a href="http://jquery.com/" target="_blank">http://jquery.com/</a> for the great documentation there about all of this ----------------------------------------------------------------------------------------------> <html> <head> <script language="javascript" type="text/javascript" src="jquery.js"></script> </head> <body> <!--------------------------------------------------------------------------------------------- 1) Create some html content that can be accessed by jquery ----------------------------------------------------------------------------------------------> <h2> Client example </h2> <h3>Output: </h3> <div id="output">this element will be accessed by jquery and this text will be replaced</div> <script id="source" language="javascript" type="text/javascript"> setInterval(function () { //------------------------------------------------------------------------------------------- // 2) Send a http request with AJAX <a href="http://api.jquery.com/jQuery.ajax/" target="_blank">http://api.jquery.com/jQuery.ajax/</a> //------------------------------------------------------------------------------------------- $.ajax({ url: 'api.php', //the script to call to get data data: "", //you can insert url argumnets here to pass to api.php for example "id=5&parent=6" dataType: 'json', //data format success: function(data) //on recieve of reply { var id = data[0]; //get id var vname = data[1]; //get name //-------------------------------------------------------------------------------------- // 3) Update html content //-------------------------------------------------------------------------------------- $('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname); //Set output element html //recommend reading up on jquery selectors they are awesome <a href="http://api.jquery.com/category/selectors/" target="_blank">http://api.jquery.com/category/selectors/</a> } }); },500); </script> </body> </html>
Jak mogę zrobić aby mi wyświetlało 5 ostatnich wpiów z bazy nie tylko jeden?