Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    a newbie coder. Need some help

    Hi coders,
    I'm a newbie coder and need some help regarding PHP.

    I've visited some sites developed with PHP and I saw this code earlier.

    Code:
    Eg:
    www.somesite.com/products/productcategory.php?cid=19
    
    www.somesite.com/pg=publication
    
    www.somesite.com/pg=reports
    It seems that they're trying to hide the actual page link and show by the means of "pg=page1, page 2, and so on".

    What does this code return and what are the advantages of using this way:

    Code:
    ....productcategory.php?cid=19
    How would I make my site using the code above?

    Please help me and I'm getting a hang of PHP

    Thanks much in advance.

    Cheers!

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    productcategory.php?cid=19

    tells the page to pull a category out of a database with the ID of 19

    www.somesite.com/pg=publication

    is the equivilent of index.php?pg=publication this is most likely telling a wrapper page(index.php) to load a specific include.

    so for example i use home.php?p=home in one of my sites. home.php has a select statement like this that tells it which include page to include in the main site

    PHP Code:
    if (!isset($_GET['p'])) {
        include 
    "pages/corphome.php";
    } else {
    switch (
    $_GET['p']) {
        case 
    "home":
             include 
    "pages/corphome.php";
        break;
        case 
    "mycompany":
             include 
    "pages/mycompany.php";
        break;
        case 
    "myoffers":
             include 
    "pages/myoffers.php";
        break;
        default:
             include 
    "pages/corphome.php";
        };

    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi hinch,
    Thanks a lot for the reply and helping me.

    How would I embed this code in my HTML page.

    Say I've three links:
    1. About Me
    2. Blog
    3. Portfolio


    How would I incorporate the PHP code in my page.

    eg: www.mysite.com/pg=about_me

    Moreover, do I need to use this code in all my pages?
    PHP Code:
    if (!isset($_GET['p'])) {
        include 
    "pages/corphome.php";
    } else {
    switch (
    $_GET['p']) {
        case 
    "home":
             include 
    "pages/corphome.php";
        break;
        case 
    "mycompany":
             include 
    "pages/mycompany.php";
        break;
        case 
    "myoffers":
             include 
    "pages/myoffers.php";
        break;
        default:
             include 
    "pages/corphome.php";
        };

    Thanks again.
    Last edited by newbie_coder; 12-03-2008 at 06:11 PM.

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    right your 3 links would be something like this

    pg=aboutme
    pg=blog
    pg=portfolio

    you would have an index.php file that contained this

    PHP Code:
    if (!isset($_GET['pg'])) {
        include 
    "pages/index.php";
    } else {
    switch (
    $_GET['p']) {
        case 
    "home":
             include 
    "pages/index.php";
        break;
        case 
    "aboutme":
             include 
    "pages/aboutme.php";
        break;
        case 
    "portfolio":
             include 
    "pages/portfolio.php";
        break;
        case 
    "blog":
             include 
    "pages/blog.php";
        break;
        default:
             include 
    "pages/index.php";
        };

    You would then create a pages folder and in there put your 4 pages
    index.php, blog.php, aboutme.php, portfolio.php

    those files would contain your page code.

    however the advantage of using a system like this is that you don't need to put anything between <html> and <body> tags in every page

    so your main index.php would be something like

    PHP Code:
    <html>
    <head>
    <title>blah</title>
    </head>
    <body>
    <?php
    if (!isset($_GET['pg'])) {
        include 
    "pages/index.php";
    } else {
    switch (
    $_GET['p']) {
        case 
    "home":
             include 
    "pages/index.php";
        break;
        case 
    "aboutme":
             include 
    "pages/aboutme.php";
        break;
        case 
    "portfolio":
             include 
    "pages/portfolio.php";
        break;
        case 
    "blog":
             include 
    "pages/blog.php";
        break;
        default:
             include 
    "pages/index.php";
        };
    }  
    ?>
    </body>
    </html>
    and the pages within your pages folder contain just the content like. so for example your pages/index.php would be something like this.

    PHP Code:
    <h2>this is an index page</h2>
    <
    p>body content goes here</p
    No need for any of the rest of the rubbish as thats already included on your index.php file.

    This method is handy for doing things like location aware menu's, breadcrumb systems, etc and allows you to make one change to the primary index that then propogates across the entire site.
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #5
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi hinch,
    Sorry to bother you again. I worked on procedure and the codes like you had said but it's not working. I'm getting an error 404 page not found.

    Here's what I did.

    In the root folder I created a file "index.php" which contains this code:

    Code:
    <html>
    <head>
    <title>blah</title>
    </head>
    <body>
    <?php
    if (!isset($_GET['pg'])) {
        include "pages/index.php";
    } else {
    switch ($_GET['p']) {
        case "home":
             include "pages/index.php";
        break;
        case "aboutme":
             include "pages/aboutme.php";
        break;
        case "portfolio":
             include "pages/portfolio.php";
        break;
        case "blog":
             include "pages/blog.php";
        break;
        default:
             include "pages/index.php";
        };
    }  
    ?>
    </body>
    </html>
    And I created a folder named "pages" and inside this folder I created "index.php, blog.php, aboutme.php, portfolio.php".

    And the "index.php" file inside the folder "pages" contains this code:

    Code:
    <h2>this is an index page</h2>
    <p>body content goes here</p>
    <a href="pg=aboutme">About Me</a>
    Please check this link:
    Code:
    <a href="pg=aboutme">About Me</a>
    Is this correct? Cos, when I click on the About Me link I get an error saying "The requested URL was not found on this server"

    Sorry to bother you again hinch. Please assist me. I would be grateful to you.

    Thank again.

  • #6
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    when you click the link what does it say in the url bar of the browser.

    try <a href="?pg=aboutme">About Me</a>

    failing that you may have to actually use the full page

    <a href="index.php?pg=aboutme">About Me</a>

    depends if apache is setup with mod_rewrite and such on the servers you were looking at before could be your web server setup is just a standard one so no rewrite or rules inplace for defaulting the page to index.php
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #7
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks a lot hinch. It's working now when I changed this line of code

    PHP Code:
    switch ($_GET['p']) { 
    to

    PHP Code:
    switch ($_GET['pg']) { 
    Is it correct or am I not getting something?

    Both the methods,


    1.
    Code:
    <a href="?pg=aboutme">About Me</a>
    2.
    Code:
    <a href="index.php?pg=aboutme">About Me</a>
    is working fine.

    What's the advantage of using this method?

    Moreover, like I said earlier the method

    Code:
    www.somesite.com/products/productcategory.php?cid=19
    how would I go about to setup a site using this method? Let's say for example, I'm going to setup a news website and there are many categories, do I need to give manually the "cid" code for the links.

    Eg:

    1. <a href="/newscategory.php?cid=1">Local news</a>
    2. <a href="/newscategory.php?cid=2">Weather</a>
    3. <a href="/newscategory.php?cid=6">Media</a>
    4. <a href="/newscategory.php?cid=9">International News</a>


    and so on.

    Thanks a lot hinch.

    Cheers!

  • #8
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    you were right to change to p to pg i must have missed that one

    for doing something like this you'd have basically a link like

    index.php?pg=newscat&cid=

    you'd then set your cid to be whatever typicaly this is done with a database lookup table to dynamically generate the link list.
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • Users who have thanked hinch for this post:

    newbie_coder (12-04-2008)

  • #9
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi once again hinch,

    you'd then set your cid to be whatever typicaly this is done with a database lookup table to dynamically generate the link list.
    Could you please give me a link where I can learn something like database lookup?

    So it means I've to fetch the "cid" manually and place them one by one in the link by myself, right?

    I hope I'm not driving you nuts

    Thanks a lot.

  • #10
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    arg now your getting complex.

    basically you'd have a table in your mysql database something like

    tblNewsCats

    In that table you'd have 2 columns.

    ID & CatName

    Then on your page that generates the links to the categories you'd select the contents of that table, loop through them echoing out the list of categories and your address ould be something like

    <a href="index.php?pg=newscat&cid=<?php echo $results[0];?>">?php echo $results[1];?></a>

    Then you'd have a page called newscat.php in your pages folder which would then retrieve the cid from the link and do another lookup against teh database table that stores all your news (a 2nd table) and links against thecategory id in that table to pull out the correct information.

    I'm really really bad at explaining things though your best bet is to hit google for "php + mysql tutorials" or something along those lines.
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  

    Posting Permissions

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