Jump to content

Recommended Posts

Basically...

I'm collecting xml data and storing it into a database. Then I'm calling that info from the database using a jquery .ajax function to load and display it on the page.. It all works fine..

 

The problem...

The xml file consists of many sports leagues with odds for each game in that league.. Right now it takes a few seconds to load all that data and put it into the database.. Now when the user goes to the odds page on the site they have to wait a few seconds for all that data to update into the database and then load to display..

 

What I would like to know...

How could I load the latest xml data into the database so that the user does not have to wait??

 

The closest I've gotten to solving...

I've tried running a cronjob every minute, which works great, but that won't work because the cronjob stops right when I turn off my computer.. I need it to run always so the users always have to most recent data.. And I'm not so sure this is the most efficient way of getting it done either..

 

There has to be some way of getting this done by using ajax or something like that, but I have no clue how to approach this.. I need some strategy.. Could anybody out there give me a few ideas as to how this might be done??

 

If I didn't give enough information just let me know and I'll try and be more specific..

 

Thanks everybody!!

 

Ahh.. I like that iframe idea to trigger an update, but this still leaves me with a question..

 

You said to initially feed them the data.. That is the data that needs to be fresh.. How would the initial feed of the data be the freshest without updating??

 

Are you saying display the old data until the new data updates and then replace it?

 

 

yeah put something like "page is not current, one moment" on the top display the old data then make a php file that will give you the content to replace the body with, then replace all the content in the body tag when it is complete, as this could give them a general idea while they wait

Well see that's basically what I've got right now.. As they enter the page they see a loading message and animated loading gif while the latest xml file is loaded and displayed..

 

This is really all that I'm trying to overcome here.. That few second wait there.. I have seen this on a couple other sites where they always have the latest odds displayed with no wait whatsoever.. I'm trying to figure out how they do that..

 

Thank you so much for the ideas!! Maybe the iframe might lead me to the answer..

Here's basically what I'm doing..

 

Database table:

CREATE TABLE `pfs_lines` (
  `id` int(30) NOT NULL auto_increment,
  `type` varchar(15) NOT NULL default '',
  `awayteam` varchar(255) NOT NULL default '',
  `hometeam` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

index.php

<html>
<head>
<style>		
#loading {
display:none;
width:32px;
height:32px;
background:url(images/ajax-loader.gif) no-repeat;
}		
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {		
$('#cur_odds').bind('change', function(){
	$('#loading').show();
	var type = $(this).val();
	$.ajax({
		type: 'GET',
		url: 'odds.php',
		cache: false,
		async: true,
		data: 'type=' + type,
		success: function(lines){
			$('#loading').hide();
			$('#display_bets').html(lines);
		}
	});
});
});
</script>
</head>
<body>
<input type="hidden" name="cur_odds" value="CFB" id="cur_odds" />
<script type="text/javascript">
$(function() {
    $('#loading').show();
    $.ajax({
        type: 'GET',
        url: 'load-odds.php',
        async: false,
        success: function(lines){
            $('#cur_odds').trigger('change');
        }
    });	
});
</script>
<div id="loading">Loading...</div>
<div id="display_bets"></div>
</body>
</html>

 

odds.php

<?php
// database connect
$r = mysql_query("SELECT * FROM pfs_lines WHERE type = '".$_GET['type']."'");
while($l = mysql_fetch_array($r)) {
echo $l['type'].' - '.$l['awayteam'].' - '.$l['hometeam'].'<br />';
}
?>

 

load-odds.php

<?php
// database connect
$XML_LINES = 'http://client.vdhinc.com/lines.xml';
$xml = simplexml_load_file($XML_LINES); 
foreach ($xml->sport as $sport) {
foreach ($sport as $game) {
	mysql_query("INSERT INTO pfs_lines (type,awayteam,hometeam) VALUES ('".$sport->attributes()->type."','$game->awayteam','$game->hometeam')");
}
}
?>

 

Well if somebody can figure out a way so one wouldn't have to wait for that to load on page load, that's what I'm looking for..

 

Thanks again!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.