josephsprint Posted May 28, 2006 Share Posted May 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/ Share on other sites More sharing options...
litebearer Posted May 28, 2006 Share Posted May 28, 2006 try enclosing your case values in double rather than single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/#findComment-39685 Share on other sites More sharing options...
ToonMariner Posted May 28, 2006 Share Posted May 28, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/#findComment-39689 Share on other sites More sharing options...
josephsprint Posted May 28, 2006 Author Share Posted May 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/#findComment-39690 Share on other sites More sharing options...
josephsprint Posted May 28, 2006 Author Share Posted May 28, 2006 OKI 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 Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/#findComment-39700 Share on other sites More sharing options...
josephsprint Posted May 28, 2006 Author Share Posted May 28, 2006 OK I'm an idiot i was putting the get part in the wrong place, it now works as expected. Thanks loads. Quote Link to comment https://forums.phpfreaks.com/topic/10639-php-dynamic-content-switching-help-please/#findComment-39702 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.