Jump to content


Photo

PHP Help!


  • Please log in to reply
10 replies to this topic

#1 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 08 July 2005 - 10:44 AM

Hi there.

I have just started using PHP and I need some help please.

I found this website the other day at http://www.xneopians...uide_phpinclude

I tied following the tutorial on PHP Include but it does not work for me. Here is the code to the tutorial below.

<DELETE THIS SENTENCE BEFORE YOU USE CODE BUT NOT THE QUESTION MARK AND ARROW?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$go){ $go = $HTTP_GET_VARS['go']; }

if($go=="" or $go=="index.php"){

    include("PATH TO FILE BEING SHOWN, THIS IS YOUR PAGE WHICH AUTOMATICALLY SHOWS UP ON THE FRONTPAGE OF YOUR SITE");
}elseif($go=="PAGENAME"){
include("PATH TO FILE BEING SHOWN");

}
?>
</p>




What do you have to put in the PAGENAME and the PATH TO FILE BEING SHOWN part.


Plus does the webpage have to be online to work or can you work offline.

Hope someone with great PHP Skills can help me out. Thanks in Advance.

#2 softLearner

softLearner

    Young Padawan

  • Members
  • Pip
  • 128 posts

Posted 08 July 2005 - 11:07 AM

First of all this code here:
include("PATH TO FILE BEING SHOWN, THIS IS YOUR PAGE WHICH AUTOMATICALLY SHOWS UP ON THE FRONTPAGE OF YOUR SITE");

Replace the text in capital letters between the quotation marks and just do this: index.php

next this line:
}elseif($go=="PAGENAME"){
Replace PAGENAME with home

then this line of code here:
include("PATH TO FILE BEING SHOWN");
Replace the text that is in capital between the two quotetaion marks again and put home.php instead.

So now you code should look like this:

<?php

if(!$go)
{
    $go = $_GET['go'];
}

if(!$go)
{
    include("index.php");
}
elseif($go=="home")
{
    include("home.php");
}
?>
<a href="index.php?=home">Home</a>
Now save that code as index.php and create a new file called home.php and just add this code:
<?="Welcom to home.php!"?>

Now goto http://localhost/ and you should find a link with Home, click home and what ever you included in home.php should now be visible.
This site here is a good start for you as it tells you how to use PHP on your PC.

Edited by softLearner, 08 July 2005 - 11:11 AM.


#3 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 08 July 2005 - 12:01 PM

Thanks for the information softLearner but it did not work.

Do I have to download the programs from the site you given me (Installing Apache PHP and MySQL) on to my computer to made it work.

I am using Dreamweaver Mx 2004.

#4 greg

greg

    Jedi In Training

  • Members
  • PipPip
  • 499 posts
  • Location:New York City
  • Interests:Fine art, web and graphic design, naval architecture, chess, and sports.

Posted 08 July 2005 - 01:03 PM

No, you don't have to download anything.

I'm not an expert with PHP, but I know enough to tell you that the code from that X Neopians site is lousy.

What exactly do you want to do? Do you just want to include other pages in your page (kind of like an iframe)? Or do you want to have all of your pages be brought up through a variable (like index.php?loc=aboutus, index.php?loc=contactus)?

If you just want to include another page in yours, it only takes a few key strokes:
<? include("filename.php"); ?>
What this does is include the file filename.php seamlessly into the current page. This is very useful with menus, and other things that you might have to change often. Because instead of having a menu on each page, just write the code above in the place of the menu on each page, and put the menu itself in a file of its own, such as menu.php. If the time comes to edit something in your menu, you simply change it in the file menu.php, and all the rest change too (since they all include that file).

What I meant by "seamlessly," is it acts like it is in the actual page it's being included in. So if your page links to a CSS file that has something like:
#menu {background:#00f;}
... And that page also includes menu.php, in which you have:
<div id="menu">...</div>
... The menu will have the background color #00f. Basically, it acts as if it's in the page, but it isn't!

Edited by greg, 08 July 2005 - 01:05 PM.


#5 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 08 July 2005 - 01:39 PM

Hi Greg

What exactly do you want to do? Do you just want to include other pages in your page (kind of like an iframe)?


Yes I want it so the index page and the nav stay the same but the content of each page changes.

I just tied your example but it still does not work.

Maybe you could sent me a example template via email please.

Thanks in advance.

#6 greg

greg

    Jedi In Training

  • Members
  • PipPip
  • 499 posts
  • Location:New York City
  • Interests:Fine art, web and graphic design, naval architecture, chess, and sports.

Posted 08 July 2005 - 01:53 PM

OK, then what I wrote isn't going to do it. You have to use a switcher to switch which file is being included.
<?php
//session has to be started before html output
session_start();

echo"<html>\n";
echo"<head>\n";

if(isset($_GET['loc']))
    {
        $_SESSION['loc'] = $_GET['loc'];
    }
elseif(!isset($_GET['loc']) && !isset($_SESSION['loc']))
    {
        $_SESSION['loc'] = 1;
    }

if(isset($_SESSION['loc]))
    {
      switch ($_SESSION['loc']) {

       case "1": $location = 'home.php';
       break;
                             
       case "2": $location = 'page2.php';
       break;
                             
       case "3": $location = 'page3.php';
       break;
                             
       default: $location = 'home.php';
       break;
       }
     }
?>

</head>
<body>

<a href="index.php?loc=1">Home</a><br />
<a href="index.php?loc=2">Page 2</a><br />
<a href="index.php?loc=3">Page 3</a><br />
<? include("$location"); ?>
</body>
</html>
I think that should work. Let me know.

Edited by greg, 08 July 2005 - 01:54 PM.


#7 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 08 July 2005 - 03:22 PM

Hi again greg

No still can not get it to work for some reason.

Thanks anyway.

#8 Jynxis

Jynxis

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:The Shadows

Posted 09 July 2005 - 01:22 AM

there are a few ways to do it...

now i wont go into detail...

#1
<php
$id =""; // default

if (isset($_GET['id'])) $sid = $_GET['id'];

if (($id == "")) {

$page_title = "Home";

include ("main.php");

echo"<html>
<head><title>$page_title</title>";

}

if (($id == "about us")) { //It should put the space chars in there

$page_title = "$id";

include ("about_us.php");

echo"<html>
<head><title>$page_title</title>";
}

?>

then theres switching

#2
                        
<?php
	$id = " ";
switch (@$_GET['id']) { 
#stuck the @ there to supress the error try without the @ and have $id = NULL;

case "about_us":

inlcude("about_us.php");

$page_title = "about us";

echo"<html>
<head><title>$page_title</title>";
   
break;

default:

include("main.php");

$page_title = "Home";

echo"<html>
<head><title>$page_title</title>";

break;

}

?>



try it out.. and change wut you need.... add wut you need... should work... i use both examples all the time.

Edited by PlaGuEX, 09 July 2005 - 02:51 PM.


#9 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 11 July 2005 - 11:45 AM

Hello there.

I still dont't know how to it. I tied all the examples below.

I found this example http://www.celtek.ne...webbiescat.html

Does it work for you. If so can you please help me.

Do you need to put the php files online to make them work.

Thanks guys.

#10 softLearner

softLearner

    Young Padawan

  • Members
  • Pip
  • 128 posts

Posted 11 July 2005 - 12:27 PM

user_f_ps_other

You can do it online yes, but for a free and much better way download a software package like i said in my post.

PHP is a server sided language, whhich means it can only be run on a server environment and not the client (which is your browser)

Also goto this site here http://www.php-mysql-tutorial.com/ for tutorials on PHP and MySQL whcih will teach all the basics of PHP and MySQL and to set up Apache and MySQL too on your local PC.

#11 user_f_ps_other

user_f_ps_other

    Young Padawan

  • Members
  • Pip
  • 173 posts

Posted 11 July 2005 - 12:55 PM

Hello softLearner

Thanks for the reply so fast. I don't know you needed a program to run php.
anyway just a other quick question what program should i download it's got

PHP 5.0.4 (tar.bz2) [4,620Kb] - 03 Apr 2005
md5: fb1aac107870f897d26563a9cc5053c0

PHP 5.0.4 (tar.gz) [5,702Kb] - 03 Apr 2005
md5: 8edf259bcfab4cfc890a4bb4e7c3649f

whats the diff.

ps

Is the php program above the only program I will need to use the php inculde.

anyway thanks mate for all your help softLearner cu around.

Thanks again guys.

edit:
I've got the offline sever to work now. But i tied this tutorial (php include) at
http://www.subound.c...hp?showtopic=68

I followed the tutorial, the news page comes up in the content area of my website.
But how do i get the other pages to go into the area (i.e when the tutorials button is pressed the tutorial content goes into the area the code as been placed on the main page.

Thanks

don't double post. ~rc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users