i want it to search the whole databse table

Discussion in 'PHP' started by babyphp, Apr 15, 2008.

  1. #1
    i can only use this code to search for firstname, i want it to search the whole databse table

    how do i do that

    $search=$_POST["search"];

    $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%'");

    while($row=mysql_fetch_array($result))

    {


    $firstname=$row["firstname"];
    $lastname=$row["lastname"];
    $email=$row["email"];
    $phone=$row["phone"];


    echo "$firstname <br> $lastname <br> $email <br> $phone <br>";
     
    babyphp, Apr 15, 2008 IP
  2. JLEville

    JLEville Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use this for you're mysql query. It should work.


    $result = mysql_query("SELECT * FROM contacts WHERE firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%'");
     
    JLEville, Apr 15, 2008 IP
  3. babyphp

    babyphp Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you are are star
    my hat off jleville

    that works you can believe have been googling all day

    can i ask you for one more favour pls

    from my code you can see that the data would come out in a table like format
    like this

    firstname, lastname, phone, email
    how do i do this
     
    babyphp, Apr 15, 2008 IP
  4. PCaine

    PCaine Peon

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    mysql is quite easy once you get a hang of getting all the data needed for what you specifically want. MYSQL is extremely flexible!
     
    PCaine, Apr 15, 2008 IP
  5. JLEville

    JLEville Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    JLEville, Apr 15, 2008 IP