Close

Page 1 of 2 12 LastLast
Results 1 to 20 of 30
  1. #1
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default A little basic PHP help...

    Basically with PHP I beleive you can run a few pages on one actual file, I was wondering how you do this, example on a friends site she has a link which targets "index.php?page=home" I'm guessing this runs a section labelled "home" from the index.php page, how do you go about doing this?

    Chris
    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  2. #2
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    easiest way i can think of is have an ifram called home on yer page, then when u link like target =home it opens whatever page you link to in the home iframe

    It's not php that does it, it's just standard html, php is scripting, all links are still handled with html code!

    <ifram name="home"></iframe

    Moses

  3. #3
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default Re: A little basic PHP help...

    Hmm I'm sure its a php thing, example look at my friends site (www.michellez.net) if you hover over her links you should see what I mean.

    Cheers,

    Chris.

    BTW... hows the hosting account goin?
    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  4. #4
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    if you are on about having 1 menu file and having it on every page then you can do it like this (forgot about this aint done it for a while):


    PHP Code:
    <? php include "menu.php" ?>
    have that in your file werever you want the file to appear i.e in a table data tag for example:

    PHP Code:
    <td><?php include "menu.php" ?></td>
    not too sure about the way yer mates done it, i tried that but found it messy at times so my way i found easier!

    btw thanks for the server :thumbs

    Moses
    Last edited by ShadowMoses; 2nd November 2004 at 11:54 AM.

  5. #5
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default Re: A little basic PHP help...

    its something like this

    <?php
    case about:
    this is the about page content
    break;
    case blog:
    this is the blog page content
    break;
    case contact:
    this is the contact page content
    break;
    default:
    homepage content
    }
    ?>

    any idea? she says u can have the whole site on one file if u wished.

    no probs bout the hostin!
    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  6. #6
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default Re: A little basic PHP help...

    I tried this and all I get is an error.

    <html>
    <head>
    <title>Test</title>
    </head>

    <body>
    <?php
    case about:
    {
    This is the content from the "About" page.
    }
    break;

    case car:
    {
    This content is from the "Car" page.
    }
    break;

    default:
    {
    Default content
    }
    ?>
    </body>
    </html>
    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  7. #7
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    whats the error mate??

    Moses

  8. #8
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    Just had a fiddle with yer code mate, basically your case statement was slightly wrong, you need to call the switch() function before hand to tell it to switch from one case to another!

    AND.... because you are using the page variable in the url the bnit in the brackets needs to be $_GET[page], so it gets the value of page from the url!

    Anyway this code below works, any more problems with it let me know :thumbs

    PHP Code:
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <a href="tester.php?page=default" class="mainpage">home</a><br>
    <a href="tester.php?page=about" class="mainpage">about</a><br>
    <a href="tester.php?page=car" class="mainpage">car</a><br>
     
    <?php
    switch ($_GET[page]) {
    case 
    "about":
    echo 
    "This is the content from the About page";
    break;
     
    case 
    "car":
    echo 
    "This content is from the Car page.";
    break;
     
    default:
    echo 
    "default content.";
    break;
    }
    ?>
     
     
    </body>
    </html>
    Also the web hosting, i try ftp'ing in using smartftp and it says my username is incorrect, if i do it in the browser it doesnt ask for a username and showes 2 folders with notrhing in them!

    Moses
    Last edited by ShadowMoses; 2nd November 2004 at 11:55 AM.

  9. #9
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default Re: A little basic PHP help...

    Hmm... I'll look into it.

    Thanks for the PHP Help... in each case does everything need to be in an echo statement or can you do it like this...

    PHP Code:
    switch ($_GET[page]) {
    case 
    "about":
    This page is about me.<br>
    Blah blah!
    break; 
    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  10. #10
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: A little basic PHP help...

    Don'y have everything all codeded into one page. This will be a very bad way to do it, and will be terrible to maintain!!!

    Here is what I'd suggest... Have several seperate pages for home, contact etc (home.php, contact.php...) and then in your index page, have your switch statement along the lines of:

    Code:
      switch (page)
      {
        case "home" :
      	$location = "home.php";
      	break;
        case "contact"
      	$location = "contact.php";
      	break;
     //etc
     //etc
     default:
     	$location = "home.php"
     	break;
      }
      
      include($location);
    That way the code will still be located in the index.php however only the code for the page you need is there. Also, if you are thinking about having the page in tables, then think about having this setup inside the table with the menu/header already set in there, so you're not calling it each time - optimization!

  11. #11
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: A little basic PHP help...

    Oh, sorry, forgot to say...
    If you do decide to do it the original way, then yes, everything will have to be an echo statement unless you end the php code with "<?"
    If you do it the way I suggested, all the linked pages are just coded in html.

  12. #12
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    yes everything has to be an echo statement, if not it tries running the code:

    this is the car page

    which isn't valid php syntax :tongue

    and agree with john, seperate pages with includes is better, thats the reason for my above statement saying i never use this!! seperate files is neater and easier to maintain :thumbs

    Moses

  13. #13
    DF Admin xdam's Avatar
    Join Date
    Oct 2000
    Location
    Stoke
    Posts
    1,481
    Thanks
    163
    Thanked:        183
    Karma Level
    368

    Default Re: A little basic PHP help...

    This is how I would do it...

    PHP Code:
    <?
    if ($page == page1) {
    echo
    "hello, this is page 1.";
     
    } elseif (
    $page == page2) {
    echo
    "hello, this is page 2.";
     
    } elseif (
    $page == more) {
    echo
    "you can add loads of these :).";
     
    } else {
    echo
    "index page.";
     
    }
    ?>
    any help to you? :thumbs

  14. #14
    DF VIP Member ShadowMoses's Avatar
    Join Date
    Oct 2003
    Location
    Wales, UK
    Posts
    1,168
    Thanks
    0
    Thanked:        0
    Karma Level
    309

    Default Re: A little basic PHP help...

    yeah the if is an easier way of woprking the switch statement, people seem to find understanding it easier...

    remember the first time i was shown a switch statement it confused the hell out of me

    Moses

  15. #15
    DF Rookie iwgunter's Avatar
    Join Date
    Oct 2004
    Location
    Harlow
    Posts
    14
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default Re: A little basic PHP help...

    The text you want displayed needn't be in the echo tag, I use the following all the time:

    Code:
    <? if ($page == page1) { ?>hello, this is page 1.
    <?php } else if ($page == page2) { ?>hello, this is page 2.
    <?php } else if ($page == more) { ?>you can add loads of these
    <?php } else { ?>index page<?php } ?>

  16. #16
    DF Admin xdam's Avatar
    Join Date
    Oct 2000
    Location
    Stoke
    Posts
    1,481
    Thanks
    163
    Thanked:        183
    Karma Level
    368

    Default Re: A little basic PHP help...

    Quote Originally Posted by iwgunter
    The text you want displayed needn't be in the echo tag, I use the following all the time:

    Code:
    <? if ($page == page1) { ?>hello, this is page 1.
    <?php } else if ($page == page2) { ?>hello, this is page 2.
    <?php } else if ($page == more) { ?>you can add loads of these
    <?php } else { ?>index page<?php } ?>
    true,you could also put $page1 in an echo statement and call whatever is in the url.

  17. #17
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: A little basic PHP help...

    ^True - thats why I said it will need to be in echo, UNLESS tey end it with "<?"

    I do think that it is still better to use separate pages. You get a far more structured site which is easier to manage and maintain

  18. #18
    DF Admin xdam's Avatar
    Join Date
    Oct 2000
    Location
    Stoke
    Posts
    1,481
    Thanks
    163
    Thanked:        183
    Karma Level
    368

    Default Re: A little basic PHP help...

    i dont use file extensions on my new sites nor do i use ?/='s i've found a way around it all

  19. #19
    DF Probation itschris's Avatar
    Join Date
    Jan 2003
    Location
    Glasgow, Scotland
    Posts
    281
    Thanks
    0
    Thanked:        0
    Karma Level
    270

    Default Re: A little basic PHP help...

    This is all usefull, but how would I go about this, this is how I'd like my site to run and look.

    [COLOR=Blue]My previous car was an Ibiza 1.4 16v running at 96BHP![/COLOR]
    [IMG]http://img.photobucket.com/albums/v621/chr15b/ibizasmash_sig.jpg[/IMG]

  20. #20
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: A little basic PHP help...

    if thats how you want it then I would suggest doing it a different way using includes.

    Have a header.php, and foot.php.

    in header.php have the table code for logo, nav liinks and recommended sites, and the start of the main content. Then in the footer have the closing for these tables and for the footer. Then each page you just do like this:

    Code:
     <?php include("header.php"); ?>
      HTML HERE
     <?php include("footer.php")l ?>

Page 1 of 2 12 LastLast

Similar Threads

  1. Visual Basic 6
    By Digi Program in forum Website Coding & Graphics
    Replies: 2
    Last Post: 15th October 2002, 08:11 PM
  2. Batman vs Superman - basic plot info
    By webslinger2k in forum Movie Talk
    Replies: 2
    Last Post: 4th October 2002, 10:04 PM
  3. visual basic 6 enterprise
    By spade2001 in forum Programming
    Replies: 21
    Last Post: 14th September 2002, 10:51 AM
  4. Basic P4 Setup Suggestions
    By wizer in forum PC Hardware
    Replies: 0
    Last Post: 9th September 2002, 12:00 PM
  5. Visual basic Any one!
    By magic1 in forum The Dog and Duck
    Replies: 2
    Last Post: 8th September 2002, 02:05 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •