Extracting specific data from database?

Discussion in 'PHP' started by scm22ri, Jun 26, 2012.

  1. #1
    Hi Everyone,

    How do I extract specific data from a database without having to write hundreds of different mysql commands?

    For example, if I want to extract then display only "car dealers" in New York City on my "New York City Page" --->> mydomain.com/new-york-city/used-cars. How would I make a script that will only "pull" or "extract" new york city car dealers without having to write different mysql commands?

    Thanks
     
    scm22ri, Jun 26, 2012 IP
  2. Simple Boot

    Simple Boot Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why would you need multiple SQL queries for this ? Please be more specific.
     
    Simple Boot, Jun 26, 2012 IP
  3. scm22ri

    scm22ri Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #3
    scm22ri, Jun 26, 2012 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    You obviously have never read a single article on mySQL.

    mySQL is searchable right out of the box via SQL queries. You don't need to execute 1,000 queries to fetch a result set. In most cases you just need 1.

    You questions leaves us to make ASSUMPTIONS and GUESSES about your database when we know nothing about it.

    So to answer your vague question you would use the SELECT function to fetch results. Like so:

    SELECT dealer_name, dealer_make, dealer_address, dealer_state FROM Dealers WHERE dealer_state = 'NY';

    Assumptions:
    1) You have a table named "Dealers"
    2) Your database is set up with at least the following columns: dealer_name, dealer_make, dealer_address, dealer_state
    3) dealer_state holds a 2 character state prefix
    4) You want to display all dealers from the state of New York.
     
    NetStar, Jun 26, 2012 IP
  5. scm22ri

    scm22ri Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #5
    I want to display all dealers on my website but if a dealer is from NYC then I want to have a "NYC" page on my website. If a dealer is from Los Angeles then I want to have a "LA" page on my website. On my "NYC" and "LA" pages I only want dealers from those locations.


    Here is my data. I have a name, address, state and city columns.


    http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/table.php


    What I'm trying to do is "make" or "dynamically" build pages that correspond with locations/dealers.


    If a dealer in my database is from NYC then I want my php script to build a page that targets dealers from NYC.


    If a dealer is my database is from Los Angeles California I want my php script to build a page that targets dealers in Los Angeles without having to manually make a mysql indivually to extract specific dealers in LA.


    I want my mysql statement to be generic so that it extracts dealers from every state/city and I'm "guessing" I would have to make a php script that would allow me to "make" or "build" those types of pages. Are I correct?
     
    scm22ri, Jun 27, 2012 IP
  6. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #6
    You are still using the SELECT statement in my example to display the content accordingly. Just replace my column names with yours.

    If you want to list all States and Cities you will need a "Zipcode Database".
     
    NetStar, Jun 27, 2012 IP