php help...

  • Thread starter Thread starter -
  • Start date Start date
F

Fusionhost Group

Any ideas why the last link is not working?

Code:
    <?php
if&#40;empty&#40;$page&#41;&#41; &#123;
		include&#40;'include/news.php'&#41;;
	&#125; else &#123;
	if&#40;$page==home&#41; &#123;
		include&#40;'include/news.php'&#41;;
	&#125; elseif&#40;$page==products&#41; &#123;
		include&#40;'include/products.php'&#41;;
	&#125; elseif&#40;$page==contact&#41; &#123;
		include&#40;'contact.html'&#41;;
	&#125;
&#125;
?>

Is it because I have two elseif's?
note the others work, just the last one...

Thanks :)
 
Shouldn't it be...
Code:
include&#40;'include/contact.html'&#41;;

Also, you might want to consider 'require()' rather than include - i.e. cause a fail if they don't exist.
 
Upvote 0
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.
 
Upvote 0
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 :)
 
Upvote 0
Once you have sorted the includes out try this code instead

Code:
<?php

$mypath = "include";

switch &#40;$page&#41; &#123;
case "home"&#58; include "$mypath/news.php"; break;
case "products"&#58; include "$mypath/products.php"; break;
case "contact"&#58; include "contact.html"; break;
default&#58; include "$mypath/news.php";
&#125;

?>

Cleaner and more efficient.
 
Upvote 0
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
 
Upvote 0

Latest Articles