Jump to content

PHP Dynamic content switching help please


josephsprint

Recommended Posts

Hi,

I followd a very simple tutorial on dynamic content and I can't seem to get it working even though it appeared to be the same. This is my first go at PHP.

Can anyone help me solve what's going wrong.

[a href=\"http://www.josephsprint.co.uk/test/mono/reviews.php\" target=\"_blank\"]http://www.josephsprint.co.uk/test/mono/reviews.php[/a]

following code points to a few include files in the same directory.

[code]
<div id="side1">
<h2>CD Reviews</h2>
<?php switch($id)
{
case ’issue1cd’:
include ’issue1cd.php’;
break;
case ’issue2cd’:
include ’issue2cd.php’;
break;
case ’issue3cd’:
include ’issue3cd.php’;
break;
case ’issue4cd’:
include ’issue4cd.php’;
break;
default:
require ’issue1cd.php’;
}
?>
</div>
[/code]

This is the include file- 'issue1cd.php'

[code]
<ul>
<li>White Light Parade</li>
<li>Ruby Tombs</li>
<li>This Et Al</li>
</ul>
<p>
Issue:
<a href="reviews.php?id=issue1cd">1,</a>
<a href="reviews.php?id=issue2cd">2,</a>
<a href="reviews.php?id=issue3cd">3,</a>
<a href="reviews.php?id=issue4cd">4,</a>
<a href="reviews.php?id=issue5cd">5,</a>
</p>
[/code]

It seems simple enough but I don't know what's wrong.

I would also like to know if I can put my includes into a folder called includes, in that case what does 'case' point to?

Cheers,
Jo
It appears that register globals is off (which is good!)

in that case you will need to do this...
[code]<?php
$id = $_GET['id'];

switch ($id)
{
case 'issue1cd':
  include 'issue1cd.php';
  break;
case 'issue2cd';
....
}
?>[/code]
Hi, Thanks for the replys, the double quote worked perfectly but only when appplied to everything, also when I add the $id = $_GET['id']; it just makes the screen go blank but it works without anyhow.

I don't know what globals are or what on/off means.
OK

I fixed the syntax of the script, it now looks like:

[code]
<?php switch($id)
{
    case "issue1cd":
    include ('issue1cd.php');
    break;
    case "issue2cd":
    include ('issue2cd.php');
    break;
    case "issue3cd":
    include ('issue3cd.php');
    break;
    case "issue4cd":
    include ('issue4cd.php');
    break;
    default:
    require ('issue1cd.php');
}
?>
[/code]

If I add [b]$id = $_GET['id'];[/b] to the top of the script it stops working all together and just shows a blank page.

Now this is the bit I missed before. The switching isn't actually working anyway, each link just displays the default include even though the address bar changes. I made each include different now to make sure.

Many Thanks

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.