Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: Dynamic images

  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    3
    Member #
    12485
    Hello all.
    I am working on a local directory website (i am a web design noob) and im having trouble designing a search system.
    All the businesses will be in a database and displayed on a results page, but if someone searches for something that is in a certain catagory (ie a Hotel) i want to have some hotel ads on the page.
    Would anyone be able to tell me how i can have images that dynamically change based on the results that are displayed.

    If failing that maybe i could add a search box on my main page, when a user enters a search (ie Plumber) the plumbers page could have keywords for it and the user could be sent straight to that page rather than a list of links like a normal search engine. Is that possible?
    Sorry if i havnt made alot of sense as i said im fairly new to databases and searches.

    Thanks

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey, welcoe to wdf.

    A client of mine asked for the same (matches your first question). How I did it was, I defined an array for each category (in your post, they are Hotels and Plumbers).

    So our array would look like
    Code:
    [0] = Hotels
    [1] = Plumber
    Then, I looped through the length of the array, and inside that I looped through the length of the searched string. (If they entered "Hotels in England" the length is 3).

    So inside the loops I check for a match, and if I find one, you could either define some variables for your images, [first question] or you could send the user to an appropriate page [second question].

    It sounds a lot, but it is quite simple, however you will need to use a server side language.

    Let us know if you would like further help. I can post the code, but it may not be in your chosen language.

  4. #3
    Junior Member
    Join Date
    Feb 2006
    Posts
    3
    Member #
    12485
    First off thank you for such a fast reply

    To be honest i dont know any server side language (although i would like to learn, Could you sugest the best one to start learning?). It would be great if you could post the code though as it would let me have a look through it and see roughly how its done.

    I like the sound of it searching the code and sending people to the apropriate page based on there search as it seems like it would be easyer to maintain if a problem occured in the future.

    Again thanks for the help.

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Here is the array (define a new value for each category.
    PHP Code:
    $ads[0] = "hotels";
    $ads[1] = "plumber";
    $ads[2] = "handyman"
    And in this below code, $keywords is what the user searched for.

    PHP Code:
    if(!empty($keywords)) {
    $kw explode(" "$keywords); // create an array, with a space as delimeter
     
    for($i 0$i count($ads); $i++) { / for length of array
        foreach(
    $kw as $s => $v) { // for each word in $keywords
            
    if(strpos($ads[$i]), $v) { // if a word is in array[$i]
            
    echo $ads[$i]; // echo the array value - you would change this to redirect
             
    }
        }
        }
        } 
    If you have any questions post back

  6. #5
    Junior Member
    Join Date
    Feb 2006
    Posts
    3
    Member #
    12485
    Great thank you very much


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:18 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com