Jump to content

Setting up then fetching data from another internal page?


MrTIMarshall

Recommended Posts

Hello,

 

Firstly, I would like to know how to setup a page, of which you can do something alike the following;

  • mydoman.com/InteractiveMapDataFetch.php?=COUNTRY=United-Kingdom&Region1=England - Fetches England Data
  • mydoman.com/InteractiveMapDataFetch.php?=COUNTRY=United-Kingdom&Region1=England&Region2=North-West - Fetches England, North-West Data
Each page will have code on to be fetched by the bigger document, just plain code with no styling as the style sheet is attached to the bigger document and whatnot. This is my idea on how to have my massive page, not be so massive in code at a singular time to enhance loading speeds and whatnot.

 

Secondly, I would like to know how to have a content switcher via a link click where the current data will be removed and the new data will be loaded.

 

Could someone please help me make a very basic version of this to get to grips with and then implement it into my website?

 

Thank you for any time spend in following up my question and for any help and/or advice given.

 

Best Regards,

Tim
Link to comment
Share on other sites

Having a page that has several widgets on it that in it's own queries an URL is gonna be painfully slow. What is it exactly that you want to build?

Secondly, I would like to know how to have a content switcher via a link click where the current data will be removed and the new data will be loaded.

You mean like with Ajax?
Link to comment
Share on other sites

For your first question, you would make a script and use a GET request, it does not require a form, but can use one as well.

http://php.net/manual/en/reserved.variables.get.php

 

http://www.tizag.com/phpT/postget.php

 

 

For the second question, ajax as ignace stated if want it dynamic without leaving the original page.

 

https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started

Link to comment
Share on other sites

I don't think you really want to to making separate http requests to get the data you are after.

 

What I actually think your trying to do could easily be solved with functions.

 

For example:

function fetchMapData($country, $regions = array()) {
  // For real, you would generate $data from the database most likely
  // As an example though, I'm just hard coding it into the function
  $data = array(
    'england' => array(
      'south-west' => 'this is south west data',
      'north-west' => 'this is north west data'
    ),
    'ireland' => array(
      'south-west' => 'this is south west data',
      'north-west' => 'this is north west data'
    )
  );

  $out = array();
  if (count($regions)) {
    foreach ($regions as $region) {
      $out = $out[] = $data[$country][$region];
    }
  } else {
    foreach ($data[$country] as $region => $value) {
        $out[] = $value;
    }
  }
  return $out;
}

var_dump(fetchMapData('england')); // return all regions within england
var_dump(fetchMapData('england', array('north-west'))); // return just north west region
var_dump(fetchMapData('england', array('south-west', 'north-west'))); // return south west & north west region
This hides all your logic within one place, the fetchMapData() function and makes it very easy to retrieve in multiple different pages without duplicating the code everywhere.

 

Does this help?

Link to comment
Share on other sites

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.