Scooby08 Posted January 9, 2010 Share Posted January 9, 2010 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!! Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/ Share on other sites More sharing options...
ldb358 Posted January 9, 2010 Share Posted January 9, 2010 couldn't you feed them the data then have an iframe which triggers an update then when the update is complete use ajax to update the current page Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/#findComment-991411 Share on other sites More sharing options...
Scooby08 Posted January 9, 2010 Author Share Posted January 9, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/#findComment-991419 Share on other sites More sharing options...
ldb358 Posted January 9, 2010 Share Posted January 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/#findComment-991436 Share on other sites More sharing options...
Scooby08 Posted January 9, 2010 Author Share Posted January 9, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/#findComment-991443 Share on other sites More sharing options...
Scooby08 Posted January 9, 2010 Author Share Posted January 9, 2010 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!! Quote Link to comment https://forums.phpfreaks.com/topic/187778-looking-for-suggestions-as-to-how-to-do-this/#findComment-991541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.