0

Hi everyone,

For a social system I am working on, I am in desperate need of being pointed in the right direction for how to create a live ajax feed which calls data from a database.

Urgently needed, any help much appreciated!

Cheers!

Jack(Scaasiboi)

3
Contributors
3
Replies
16
Views
6 Years
Discussion Span
Last Post by dean8710
0

Look here:

http://api.jquery.com/load/

Depending on how often you want your feed to be updated you could use a Javascript setInterval() function to repeatedly call the .load ajax feed.

Here is something I've used in the past (to update a price of an item every couple of seconds).

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function updateBids() {
	var url="getprice.php?auc=<?php echo $id; ?>";
	jQuery("#priceElement")<strong class="highlight">.load</strong>(url);
}

<strong class="highlight">setInterval</strong>("updateBids()", 1000);
</script>
</head>
<body>
Here is the price: <div id="priceElement"></div>
</body>
</html>

Simple (behind-the-scenes) PHP script to fetch data from db:

<?php

// Anything printed on this page will be loaded into the priceElement <div>

                include ('db.php');

		$id = $_GET['auc'];
		$getprice = mysql_query("SELECT b_currentprice FROM bid WHERE auction_id = '$id' ORDER BY b_timestamp DESC");
		$resultprice = mysql_fetch_assoc($getprice);
		
		$price = $resultprice['b_currentprice'];
		echo $price;
?>

Edited by nonshatter: n/a

0

Cheers for that I modified the jquery slightly and altered it to work with my existing php calling script, and it works awesomely!

Cheers!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.