Jump to content


Photo

PHP Dynamic content switching help please


  • Please log in to reply
5 replies to this topic

#1 josephsprint

josephsprint
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 May 2006 - 11:45 AM

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.

<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>

This is the include file- 'issue1cd.php'

<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>

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

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 28 May 2006 - 12:48 PM

try enclosing your case values in double rather than single quotes.

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 May 2006 - 01:12 PM

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

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

switch ($id)
{
 case 'issue1cd':
  include 'issue1cd.php';
  break;
 case 'issue2cd';
....
}
?>

follow me on twitter @PHPsycho

#4 josephsprint

josephsprint
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 May 2006 - 01:21 PM

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.

#5 josephsprint

josephsprint
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 May 2006 - 01:46 PM

OK

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

<?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');
}
?>

If I add $id = $_GET['id']; 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

#6 josephsprint

josephsprint
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 May 2006 - 01:57 PM

OK I'm an idiot i was putting the get part in the wrong place, it now works as expected. Thanks loads.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users