Results 1 to 7 of 7

Thread: Easy SQL query

  1. #1

    Easy SQL query

    Hi - hopefully this is an easy query for any experts out there!

    I have a text entry on a form where someone enters a surname they want to search for and when they press the submit button the page should display the results. The page is linked to a table in a phpmyadmin database with following headings - MemberID, Title, FName, LName. The action element of the form is to go to a php page with the following code:

    include "";
    echo "<table border=1>";
    echo "<tr>";

    The include file has the SQL which I am struggling with. I have played around with a few variations - do I need to use $_POST somewhere? I need it to search the database for whatever surname is entered in the form and then return the results - can anyone help? Thanks

  2. #2
    What exactly is in the file?

    I'm not sure what you're having trouble with. I've also noticed that you're 'for' loops aren't going to reitterate because they stop when $i and $j equal 1. Have a look at this code, maybe it'll help you.

    PHP Code:

    // Connect to MySQL Server and select databse.

    // Grab the input from the HTML form
    $lastname $_POST["lastname"];

    $query "SELECT * FROM people"// People would be your table containing all this information. 

    $result mysql_query($query); // Query the database

    $num_rows mysql_num_rows($result); 

    $i 0;
    $i $num_Rows)
    mysql_result($result,$i,"LName") == $lastname)
    "First Name: ";
    "<br />Last Name: $lastname<br />Title: ";
    "<br />Member ID: ";
    "<br /><br />";


    [COLOR=dark-blue]Matt Carpenter[/COLOR]
    Offer your clients a brandable FTP upload utility

  3. #3
    Thanks Matt

    This works fine


  4. #4
    Is it necessary to always use my-sql database with PHP? please suggest your reply will be appreciated.

  5. #5
    Quote Originally Posted by nancysmith View Post
    Is it necessary to always use my-sql database with PHP? please suggest your reply will be appreciated.
    i'm not exactly sure, but it isn't necessary always, cause i edited a lot of php files without database in it..

    hope it helps

  6. #6
    i will certainly try this code

  7. #7
    Thanks for the sql stuff, I was not too good in sql but I'm learning it in forums mainly.

  8. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts