PHP If Statement - Help ;)

Associate
Joined
29 May 2005
Posts
144
PHP If Statement - RESOLVED!

Hello All.
Trying to do a similar if statement to my cold fusion one in PHP but am not sure on the syntax of PHP, as im just starting to learn it. I gave it a stab in the dark, but oviously didnt work. ;) could someone point me in the right direction. I tryed but failed. Thanks MoFish

Code:
<cfif isDefined("url.id1")>	
  <cfif #url.id1# EQ 2>
<cfinclude template="home.php">
  <cfelseif  #url.id1# EQ 3>
<cfinclude template="forum.php">
  <cfelseif  #url.id1# EQ 4>
<cfinclude template="downloads.php">
</cfif>
<cfelse>
  <cfinclude template="home.php">	
</cfif>

Code:
<if isDefined("url.id1")>	
  if ($url.id1$ == 2){
<?php include("home.php"); ?>;
  }elseif  ($url.id1$ == 3){
<?php include("forum.php"); ?>
  }elseif  ($url.id1$ == 4>{
<?php include("downloads.php"); ?>	
  <elseif>
<?php include("home.php"); ?>	
</if>
?>
 
Last edited:
Ok say you are passing the pagename in the url... (www.yourdomain.com/?url=3)

PHP:
<?php
if isset($_GET["url"]) {
	switch ($_GET["url"]) {
		case 2:
		include("home.php");
		break;
		case 3:
		include("forum.php");
		break;
		case 4:
		include("downloads.php");
		break;
	}
else
	include("home.php");
?>
 
Last edited:
Also, include a default to catch invalid parameters :)
(in which case you can also simplify the switch)
Code:
<?php
if isset($_GET["url"]) {
    switch ($_GET["url"]) {
        case 3:
        include("forum.php");
        break;
        case 4:
        include("downloads.php");
        break;
        default:
        include("home.php");
        break;
    }
else
    include("home.php");
?>
 
huston we have a problem ;)

I currently have my navigation getting its values from a navigation.php file. Inside the navigation.php file I have the following.

Code:
<p>
  &gt; <a href="index.php?url=2">Home</a>
  <br>
  &gt; <a href="index.php?url=3">Forum</a>
  <br>
  &gt; <a href="index.php?url=4">Downloads</a>
</p>

I then have an index.php file, with a main div, in which the following is located.

Code:
<?php
if isset($_GET["url"]) {
    switch ($_GET["url"]) {
        case 3:
        include("forum.php");
        break;
        case 4:
        include("downloads.php");
        break;
        default:
        include("home.php");
        break;
    }
else
    include("index.php");
?>

Is this setup correctly? I'm getting the following error when trying to load the index.php

Parse error: parse error, unexpected T_ISSET, expecting '(' in on line 57

soz, im thick ;)
 
Code:
<?php
if(isset($_GET["url"])) {
    switch ($_GET["url"]) {
        case 3:
        include("forum.php");
        break;
        case 4:
        include("downloads.php");
        break;
        default:
        include("home.php");
        break;
    }
} else {
    include("index.php");
}
?>
 
Sorry my fault!
PHP:
<?php
if (isset($_GET["url"])) {
    switch ($_GET["url"]) {
        case 3:
        include("forum.php");
        break;
        case 4:
        include("downloads.php");
        break;
        default:
        include("home.php");
        break;
    }
else
    include("index.php");
?>

Also, you have a link for 2, which isn't checked by the PHP...
 
Fully tidied & corrected:

Code:
<?php
if(isset($_GET['url'])) {

	switch ($_GET['url']) {

		case 3:
		include 'forum.php';
		break;

		case 4:
		include 'downloads.php';
		break;

		default:
		include 'home.php';
		break;
	}

} else {
	include("index.php");
}
?>

:)
 
next question is ... drumroll ... DIVS!

Should I be using fixed div's or divs with %'z! I've been trying to get this DIV in the middle of the page forever! but If i shrink the window slightly it goes all haywire, and appears to be bigger at one side form the other! ;) Also I can set it up for 1024x768 to be in the middle, but when I change to 1280x1024 it messes up again. Whats the best thing to do here? ;)

Oh heres the link incase your interested in what sorta mess im making, yep a big one ;)

LINK

Code:
<div style="position:absolute; left:20%; top:0px; width:750px; height:100px">Banner
</div>
 
Last edited:
OK, I've changed some stuff around and got the DIV's the way I want them, and started on some CSS. Ive come accross a problem however. Im trying to input text into my main section of the site, but it doesnt seem to display it at all. it's like hidden or something wierd. I'm not sure where it is. If you look at my souce code for my page, you will see the following:

Code:
Hello Why Cant I See This

Its quite neer the bottom of the source code. Im trying to display that in the main section of the page, but having no luck. I must be doing something wrong somewhere. :o

Does anyone see why this would be doing this or what I have dont wrong?

LINK TO PAGE
 
Firstly, sort out the HTML. You have a DOCTYPE and new <html> etc tags halfway into the page - not good. Those go once, at the top, with a corresponding </html> tag right at the very bottom of the document. Same goes for the <body> tag, too :)

Then sort out the indenting, then we'll talk :)
 
Ahh I see why It was doing that, because I was using an include, I forgot to take the head tags out the other page. oops! How about now?

Ahh I suck at the indenting thing! ;) :p Think its ready to talk! :p
 
Last edited:
MoFish said:
Is this a bad thing? :confused:
Only if you're using the design-view (WYSIWYG) to generate the code for your layout. It's well-known for generating bloated, outdated and invalid code.

If you're coding it yourself and only using the code-view, then it's not an issue :).
 
Augmented said:
Only if you're using the design-view (WYSIWYG) to generate the code for your layout. It's well-known for generating bloated, outdated and invalid code.

If you're coding it yourself and only using the code-view, then it's not an issue :).

Oh I See. I'm still having a problems displaying any information in my Main table. If I look at the design view on dreamweaver, its there, but when i actually look at it through the browser, its vanished! :(
 
Back
Top Bottom