Search for Year,Make,Model and get taken to different pages based on input

Discussion in 'PHP' started by Raymond_M, Jan 2, 2011.

  1. #1
    Okay, so I have a product for cars/trucks that has 14 different variations. I want users to be able to easily search by year, make, and model for which variation they will need. Once they select their year, make, and model and click submit, i want them to be taken to that products page. I would have a 14 lists and there would be many many many vehicles per list.

    I don't know php, I am learning javascript and have an understanding of how it. I have editied a php script around for a contact form that was given to me and had no problems.

    I am hoping this is simple enough that someone might throw me a bone so I can run with it or something.

    If you have any questions just ask!

    Any help is appreciated. Thanks in advance!
     
    Raymond_M, Jan 2, 2011 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    you should really use a database to store your product. You could the store year,make,model info with each product variation as well a product url, and use an sql query to select the appropriate product page.

    take for example you have a database table for your products that has the following fields:

    tblproducts{
    id
    year
    make
    model
    product
    product_page
    }

    
    $query = "SELECT product_page FROM tblproducts WHERE product='".$_POST['product']."' AND year='".$_POST['year']."' AND make='".$_POST['make'].'" AND model='".$_POST['model']."';";
    
    //get the record code depends on database used example for mysql
    $rs = mysq_execute($query) or die(mysql_error());
    
    $row = mysql_fetch_array($rs,MYSQL_BOTH);
    $page=$row['product_page'];
    mysql_free_result($rs);
    header("location: $page");
    
    
    Code (markup):
    this is a simplified example in practice a database should be designed so that you wouldn't have as much redundant data.
     
    shofstetter, Jan 3, 2011 IP
  3. Raymond_M

    Raymond_M Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I read through the entire tutorial on php in tizag.com and have a much better understanding of php now. If I do the same on MySQL I should be able to understand what you've just said better and likely write similar code myself right? Well I hope so haha. I'll be back in a few hours lol
     
    Raymond_M, Jan 3, 2011 IP