SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation :: n00b alert :: if statement? ::

    Hey peeps,

    I am familiar with PHP but have never properly coded with it and I was wondering if I could get some help with a code Iím trying to get to work.

    I'm design my first site with elements of php, mainly just using include() to call pages and so on, however, I want to make the nav (which is in the index.php) to respond to whatever page is being called. I want it to work, so that when someone click a link, and visits a page, that link becomes inactive. I'm not getting any errors anymore, and at its present state, the link is constantly inactive, no matter where I am on the site.

    Anyway, here's my code for the link.

    PHP Code:
    <?php
    if ($page="home")
    {
    ?>
    <img src="site_imgs/home_but_b.jpg" alt="HOME" name="home_link" width="64" height="25" border="0" id="home_link" />
    <?php
    }
    else
    {
    ?>
    <a href="index.php?page=home" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home_link','','site_imgs/home_but_b.jpg',1)"><img src="site_imgs/home_but_a.jpg" alt="HOME" name="home_link" width="64" height="25" border="0" id="home_link" /></a>
    <?php
    }
    ?>
    and in the "home" page, I have the following to identify it.

    PHP Code:
    <?php
    $page 
    "home";
    ?>
    As im sure you can see from there, I have rollover images as links, and I want the link, once clicked, to show the over image.

    I'm not even 100% sure that I am going about this the right way, so if anyone can either help me get this to work, or can show me an easier or better way to do it, it'd be much appricated.

    Thanks.

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    PHP Code:
    if ($_GET['page'] == "home"){
    ... 
    Notice I use == instead of = .
    = assigns, == compares.
    Also, it's better to use $_GET, as your script won't work with register_globals off.

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats f**kin sorted, aw nice one m8, I owe ya one big time.

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, there's no need to "identify" your "home" include like you say above. It gets pointed to by the link that says ?page=home ...

  5. #5
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, extending on whats above, I've tried to code it so that theres one place for an image, and depending on what page you're on, a different image is displayed, how would I do that?

  6. #6
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is what you mean:

    PHP Code:
    if ($_GET['page'] == "home"){ 
      echo 
    '<img src="home_img.gif" border="0" />';
    } else if (
    $_GET['page'] == "blog") {
      echo 
    '<img src="blog_img.gif" border="0" />';
    }

    ... 
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod


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
  •