SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2008
    0 Post(s)
    0 Thread(s)

    How do you make a site reference data on another page and update itself automatically

    i have no real experience of web design or programming, but I know very elemental things about HTML and Basic etc.

    Basically, i am a writer and am trying to create a page for a project i am working on. The catch is, the short story that i intend to show on the website changes as the stock market changes. Let me explain:

    i write loads of different versions of the story, different versions of each character etc, and as the stock market goes up and down, the website changes the version of the story that it shows.

    So, all of the paragraphs relating to a specific character in the story are linked to, say, the FTSE100 index. When the FTSE drops below a certain number, all of the linked paragraphs change to another set that i have pre-written.

    I know that it is possible to do this, i'm just not sure how. It would be along the lines of:

    If stock market larger than ???
    Print ???

    Else if stock market over ??? but less than ???
    print ???

    Else print ???

    I'm just not sure how to reference data on a website, which language to do it in, if there is a standard way of doing it, etc etc.

    Any help or advice would be much appreciated. As i say, i have never even made a 'normal' website before

  2. #2
    Twitter - @CarlBeckel busy's Avatar
    Join Date
    May 2004
    Richmond, VA, USA
    0 Post(s)
    0 Thread(s)
    This is a somewhat ambitious project for a beginner, but don't let that discourage you!

    I'll go over how I would do it...

    Three things are happening here. First, you need a source of data for your stock market information. If you're grabbing data from another site you will probably be making a connection and then downloading the data in xml format. This may sound complicated but it's really not.

    You also need to decide where the information will be processed. Whenever you view a webpage, it's put together at the server, sent over the internet, and then viewed on your computer. So you can either process the data at the server, so the finished page is sent by itself, or you can send over all the information for the different versions and then decide which version to show from the person's computer. It can be done either way, but I would do it on the server unless you have a really good reason not to.

    For processing data on the server, you will use a server side language. I like PHP, but there is also ASP, Ruby on Rails, and a handful of other options you can use to accomplish this. PHP is easy to pick up and you will find a lot of help getting started here on Sitepoint.

    The trickiest part for you will be to learn how to grab the stock market data. I haven't looked at it, but you might be able to use this:

    It just happened to show up on today and it should let you grab stock quotes from Yahoo finance without too much trouble.

    And of course you're also going to need to get a basic understanding of html. I would recommend starting with the html tutorial over at w3schools (there might be some here as well)

    Good luck, I hope this helped!

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2002
    3 Post(s)
    0 Thread(s)
    here's some file grabbing code for you (in php):

    function HTTPRequest($url, $referrer, $agent) {
    	if( $agent == '' )
    		$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20050519 Netscape/8.0.1';
    	define("CURL_TIMEOUT", 20);
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_NOBODY, FALSE);			// Return body
    	curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    	curl_setopt($ch, CURLOPT_POST, FALSE);
    	curl_setopt($ch, CURLOPT_USERAGENT, $agent);		// Webbot name
    	curl_setopt($ch, CURLOPT_REFERER, $referrer);			// Referer value
    	curl_setopt($ch, CURLOPT_VERBOSE, FALSE);			// Minimize logs
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);	// No certificate
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);		// Return in string
    	curl_setopt($ch, CURLOPT_URL, $url);				// Target site
    	$results_array['file']   = curl_exec($ch);
    	$results_array['status'] = curl_getinfo($ch);
    	$results_array['error']  = curl_error($ch);
    	return $results_array;
    $results_array = HTTPRequest('', '', '');
    if( !empty($results_array['error']) ) { echo '<p>something went wrong</p><pre>'; print_r($results_array['error']); echo '</pre>'; exit(1); }
    $file_contents_as_string = $results_array['file'];
    you then need to look into parsing the retrieved file to extract the info you want. a combination of php's strpos function ( ) other bits to get what you want from the file. i'm doing this kind of thing on an html file i'm getting from google maps, here's a snippet to give you an idea (skip down to the bottom of code after functions for reading purposes, $pos is used as an index into the string):
    function getAfterOpeningHTMLTag($html_tag, $html, $pos) {
    	$html_tag = '<'.$html_tag;
    	$pos = stripos( $html, $html_tag, $pos );
    	if( $pos == FALSE )
    		return -1;
    	$pos += strlen($html_tag);
    	$html_len = strlen($html);
    	while( $pos < $html_len && $html[$pos] != '>' )
    	return $pos+1;
    function getAfterOpeningHTMLTagNoName($html, $pos) {
    	$html_len = strlen($html);
    	while( $pos < $html_len && $html[$pos] != '>' )
    	return $pos+1;
    function notContent($html, &$pos) {
    	$pos = getAfterOpeningHTMLTagNoName($html, $pos);
    	while( $pos < strlen($html) && $html[$pos] == ' ' )
    	if( $html[$pos] == '<' )
    		return TRUE;
    		return FALSE;
    function getFirstBitOfContentText($html, &$pos){
    	while( notContent($html, $pos) )
    	$start = $pos;
    	while( $pos < strlen($html) && $html[$pos] != '<' )
    	$content = substr( $html, $start, ($pos-1) - $start );
    	return $content;
    	$pos = strpos( $html, 'Driving directions to', ); // a string i know is reliably going to be there and just before what i'm after
    	if( $pos === FALSE ) {
    		// ... handle not found
    	$pos += 21;
    	$dist_time_string = getFirstBitOfContentText($html, $pos); // get a bit of data i want to extract
    	$location = getFirstBitOfContentText($html, $pos); // another bit to extract
    	$further_loc = getFirstBitOfContentText($html, $pos); // and another
    it's all very messy, cobbled together, hopeful the html i'm extracting from doesn't change radically in structure otherwise my code will fall apart immediately. if you're getting an xml file as previous to me poster suggested, not a bog standard web page, html, then you can ignore all this extracting stuff i've posted and use code which deals with xml; that's probably a much better and easier way, but so often you're dealing with html.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts