View Full Version : php help...
Fusionhost Group
31st October 2005, 18:05
Any ideas why the last link is not working?
<?php
if(empty($page)) {
include('include/news.php');
} else {
if($page==home) {
include('include/news.php');
} elseif($page==products) {
include('include/products.php');
} elseif($page==contact) {
include('contact.html');
}
}
?>
Is it because I have two elseif's?
note the others work, just the last one...
Thanks :)
Stephen
31st October 2005, 18:16
Shouldn't it be...
include('include/contact.html');
Also, you might want to consider 'require()' rather than include - i.e. cause a fail if they don't exist.
Stephen
31st October 2005, 18:21
Oh - and what exactly are: home, products and contact (i.e. the RH value of your equality test) - are they string literals or variables? If they're string literals, you want delimiters round them.
Fusionhost Group
31st October 2005, 21:24
mate nice one, after what you were saying I just noticed the problem :)
I didn't have the include in their (includeas in the folder I was using)
Thanks :)
MichaelG
31st October 2005, 22:00
Once you have sorted the includes out try this code instead
<?php
$mypath = "include";
switch ($page) {
case "home": include "$mypath/news.php"; break;
case "products": include "$mypath/products.php"; break;
case "contact": include "contact.html"; break;
default: include "$mypath/news.php";
}
?>
Cleaner and more efficient.
Fusionhost Group
31st October 2005, 23:45
Thank you 8)
Fusionhost Group
1st November 2005, 14:58
Hello,
I have another question.. I cant describe it very well but I will try my best.
I would like to have something similar to this:
Main text
Sub text
Main text
Sub text
Only the main text appears, but once the user clicks the main text it shows the sub text.
I would like to use this to display different bikes I supply for, and then the products available appear.
Any ideas on what it’s called?
Thank you
Jon
MichaelG
1st November 2005, 15:15
Try: http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm