Jump to content

[SOLVED] Me being stupid with url variables and using them.


Craigypoos

Recommended Posts

Help!  I'm pretty much a noob as far as php goes and I'd like to make a website for my band.  What I want to do is have a navigation panel with links (gigs, discography etc) on the index.php page that uses url variables (index.php?content=gigs for example) so that when visitors click on the link it opens up the content.

The neo-php I have so far (which obviosly I can't get to work) is something like this:


  <div id="menu">
    <a_href="http://page2.php?content=news"><img src="images/news1.gif"></_a>
    <a_href="http://page2.php?content=discography"><img src="images/discography2.gif"></_a>
    <a_href="http://page2.php?content=biography"><img src="images/biography1.gif"></_a>
  </div>
  <div id="content">
  <?php include $content.inc?>
  </div>
(Obviously I put the underscores in so that my code is displayed here!)

Like I said, I'm very much a noob, and there are probably loads wrong with my code, so if anyone can give me a laymans description (like really spell it out please!) of how to use these things I would be most grateful.

Cheers,
Craigypoos



One solusion:
[code]

<?php

if(!empty($_GET['content']))
{
$include_file = $_GET['content'].".inc";
if(file_exists($include_file))
{
  include $include_file;
}
else
{
  echo "File not found";
}
}

?>

[/code]

You can also look at the switch statement --> http://no2.php.net/manual/en/control-structures.switch.php

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.