Jump to content

Adding & Replacing variables to the URL


sparhawks

Recommended Posts

Hello. i am after some coding help, hope someonce can point me in the right direction. Passing variables via HREF and retrieving them with GET. Is there a way of appending multiplevariables to the URL?

 

<a href="?month=January">January</a>
<a href="?month=February">February</a>
<a href="?day=Monday">Monday</a>
<a href="?day=Tuesday">Tuesday</a>

 

eg. If i click the January link above my page will change to index.php?month=January. Then if i click Monday i would like my URL to change to index.php?month=January&day=Monday. Likewise if i have index.php?month=January&day=Monday and then click Tuesday i would like URL to replace day=Monday to day=Tuesday. Is this posssible at all? not sure where to start searching.

Link to comment
https://forums.phpfreaks.com/topic/176768-adding-replacing-variables-to-the-url/
Share on other sites

Sorry my question may have been unclear, your suggestion would work but I would rather keep it dynamic so users can elect to select a Month first, then if they want to drill down further they can select a Day as well. If i group them together as you suggested then i will have to provide a long list of URL's.

 

Ideally i would have a list of URL's January to December, then another list of URL's Monday to Sunday. A User can then select a month (eg. index.php?month=January) then they can select a day (eg. index.php?month=January&day=Monday). Then if they wanted to change month they could choose a new month (eg. index.php?month=February&day=Monday)

you're going to render the calendar each time a month is clicked. this gives you ample opportunity to customize the weekday links. something like:

 

/* you should always get a month parameter. i'd take the time to default
   this to the current month, but I can't remember how to do that off the top
   of my head */
$month = 'January';
if (isset($_REQUEST['month']) {
  $month = $_REQUEST['month'];
}

...

/* now you can use $month to customize the day links: */
<a href="?month=<?= $month; ?>&day=Monday>Monday</a>
<a href="?month=<?= $month; ?>&day=Tuesday>Tuesday</a>


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.