Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: PHP newbie

  1. #1
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry PHP newbie

    i am building a script for my WS but i'm not real sure how to use it. i am very new to PHP, my buddy has helped me out but i've learned more here. The PHP script if a if / else script, it is supposed to replace the flash banner i created @ the top of my pages. I created 6 gallery pages and 6 flash banners but i don't know exactly how to place. Everytime i place it it doesnt work, what am i doing wrong?

    Many thanks

    Both the scrip and page are attached.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You just want a random banner? Is that it?
    That script is incredibly complex... there are much better/easier ways of going about it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i guess u could call it a random banner but it actually is specific to the page. eg: bedroom page, bedroom banner and so on. Actually when the site was developed the pages were written in PHP but wasnt flexable enough, so it was tied to a SQL dB to make everything work right. Any suggestions?

  4. #4
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So you want to change the banner depending on what page your on? If so you could make your links like http://yoursite.com/index.php?page=bedroom

    Then your code would be like:

    PHP Code:
    if ($_GET['page']=='home' or $_GET['page']==''){ //default page
    echo "<img src="banner.jpg" />"//default banner
    }
    elseif (
    $_GET['page']=='bedroom'){ //on the bedrom page, so show bedroom banner
    echo "<img src="bedroom.jpg" />";
    }
    else{ 
    //if the link is just http://yoursite.com/index.php
    echo "<img src="banner.jpg" />";


  5. #5
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well...
    You can just call your bannersthe same name as the page and just echo them. IE: I have a page in the format of www.domain.com/index.php?page=home.php. In this case, the home banner will be home.gif:

    Code:
    <?php
    $page=$_GET[page]; 
    $banner=explode(".", $page);
    echo("<img src=\"path/to/$banner[0].gif\" alt=\"\" />");
    ?>

  6. #6
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Trying both examples, wish me luck but if understand the 2nd one correctly i am breaking the string in to an array with the explode function correct? but when the server reads it, it might get confused because I am calling .swx files as well.

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    $banners = array("banner1.gif","banner2.png","etc.");
    $random = rand(0,count($banners));
    echo "<img src=\"" . $banners[$random] . "\" alt=\"Banner " . $random . "\">";
    Not tested
    - Mike

  8. #8
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Trying the last but it looks to me that the code is to assign random banners? rather than a very specific one. Notice that the very same banner (swx file) plays on both pages, when in fact each page has it's own .swx file. My problem is i don't know exactly where to implement the code on the given page to make it work correctly, no matter which example i've tried. i have tried to clear my head and just think PHP but that doenst seem to work.

    Here are the pages in question :

    http://www.kwcabinets.com/gallery.php?gal=Kitchen

    http://www.kwcabinets.com/gallery.php?gal=Media&#37;20Room

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try the following attached file, and see if this is what you mean. First, look at the code and you will see what you need to edit.

    Hope this helps.

    Attachment 734

    Note: All I did was edit your original code above.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #10
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now, that's what i think i was after, when i tried to write it. Still won't work due to the big fat parse error, an unexpected T_string. Thanks, i'll keep chugging along.........

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
  •