1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP display from database

Discussion in 'PHP' started by tony84, Nov 6, 2008.

  1. #1
    My function site in my signature is the site in question.

    Then you fill in the search form, it displays the relevant results.
    What i would like is to generate something like a directory.

    I basically want to create a page which is a City name. For instance London, and then it display all the results from london. But i dont want it to be showing after the search button has been pressed, i would like it to display the relevant results automatically.

    Could anyone help?
     
    tony84, Nov 6, 2008 IP
  2. money4leads

    money4leads Well-Known Member

    Messages:
    117
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #2
    you have two sites in your sig. would you like check them both?

    any way

    try to use the "LIKE" in your sql statement

    ..... WHERE something LIKE '%$search%' ....
     
    money4leads, Nov 6, 2008 IP
  3. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #3
    I do, which is why i said the Function site in my signature, the other is premier league ;)

    The current code i use in the search section is
    <?php echo $resultList; ?>

    So i would need to change that to:
    <?php echo Like "London" $resultList; ?>?

    Or am i miles out?
     
    tony84, Nov 6, 2008 IP
  4. money4leads

    money4leads Well-Known Member

    Messages:
    117
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #4
    need to know the search function first
     
    money4leads, Nov 6, 2008 IP
  5. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #5
    what do you mean by that?

    I dont really understand much php
     
    tony84, Nov 6, 2008 IP
  6. varunkrish

    varunkrish Peon

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    are u trying to do autocomplete .. something like google suggest ?
     
    varunkrish, Nov 6, 2008 IP
  7. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #7
    no.

    Basically i have a load of entries in my database, i want to create various city pages.
    I want to have a page called london.php, manchester.php etc
    On london.php i would like it to display the entries from London and so on.
     
    tony84, Nov 6, 2008 IP
  8. shineDarkly

    shineDarkly Banned

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    hmm, although it sound good, your server will suffer a lot because if you do it the way like you mentioned, then you would have to do a query for every keypress
     
    shineDarkly, Nov 6, 2008 IP
  9. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #9
    ah ok.
    I suppose if that will happen then i may have to have a re-think.
     
    tony84, Nov 6, 2008 IP
  10. varunkrish

    varunkrish Peon

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    do this this then

    have a file called city.php

    pass the city.php the city via query string

    city.php?city=london & city.php?city=manchester

    now in city.php $_GET['city'] will give u london or machester

    build a search sql query based on the same

    LIKE select * from city WHERE name like '%$city%'

    hope this helps

    u can do URL rewriting if u want urls like london.html etc ..
     
    varunkrish, Nov 6, 2008 IP
  11. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #11
    thanks for that, i think that will be too difficult for me to do. But i appreciate you taking the time out. I might give it a try over the weekend.
     
    tony84, Nov 6, 2008 IP
  12. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #12
    Ive been told for SEO purposes on my site something like this would be ideal (even without the URL rewriting.

    Im wondering if someone could help expand on this for me. Im not interested in url rewriting as im sure thats more difficult and im after just creating something simple for now and build on it over time.
     
    tony84, Nov 14, 2008 IP
  13. PwrUps

    PwrUps Peon

    Messages:
    377
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #13
    You should also make sure to use $city = mysql_real_escape_string($city); to help stop injection.
     
    PwrUps, Nov 14, 2008 IP
  14. xenous

    xenous Peon

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    There are several ways.
    1- create a php file as city.php and do as told (use mod_rewrite for sure for seo urls)
    2- create a php file but get scriptname and do your query due to the name (same code but copied for each city)

    for all the query will be something like that (from your page i think each city is called via their id numbers from sql which may result in having two tables "one for cities" and "one for records")
    Select * from records LEFT JOIN (cities) ON (cities.id=records.city_id) WHERE cities.id='id_ofcity(eg. 1 for aberdeen)'
     
    xenous, Nov 14, 2008 IP