I can create dynamic pages already, and it is working, but the landing page loads very slowly.
I would really like some help. Below is how my site functions.
Let's start with a link in http://example.com/search.php
:
<?php
session_start();
//(pretend there is code here that gets, decodes, and displays data from an api)
$title = $titleFromApi;
$a = $dataFromApi;
$_SESSION['storeTitle'] = $title; // stores 'title' in a session variable
$_SESSION['store_a'] = $a; // stores 'a' in a session variable
echo '<a href="http://example.com/'. $a .'/' . $title .'> ' . $title . '</a>';
// the line above is a clickable link that will take them to the landing page
?>
Now here is the landing page (http://example.com/$a/$title
):
<?php
session_start();
$al = $_SESSION['store_a']; // stores session variable in new variable 'al'
$getter = 'http://api.somewebsite.com/dev/' . $al . '/get_these_variables';
// the line above gets data from an api using variable 'al'
// (pretend that there is code here that decodes the data)
// the code below displays the data retrieved from the api
foreach($data as $entry){
echo '
<div>
' . $entry['decoded_data_1']
. '
</div>
<div>
' . $entry['decoded_data_2'] // and so on
. '
</div>
'; // ends echo
}
?>
I just learned about sessions today (I thought it would make things faster); before, I sent the data into the address bar from search.php, then read it on the landing page to carry the variables over (cringe, I know, I am very new to php and development in general). The page load speed of the landing page has not changed.
As mentioned in a comment, in its current shape, your script cannot go faster than the response time of the queried API.
You don't say anything about the API, so it's not possible to guarantee a speed up in that area. However, if that API consistently returns the same result for the same query, you could alleviate the issue by implementing a result cache.
Basically, you should store in an persistent array the query result indexed by its parameters, and each time a query is made, check if the result is not already there. You may choose to make that array a session value, in database, or in a memory based cache mechanism, like memcache.
Each approach has it pros and cons, and choosing one solution over another will also depends on the API:
You may also combine the db and memcache, to obtain the speed of the later with the persistence of the former.
This is all assuming that you can somewhat predict if a query can be cached, and how long it will stay valid. You will also need to have some control on the server configuration, or hope that it already supports the functionalities discussed above.