Results 1 to 5 of 5

Thread: search

  1. #1

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909

    search

    PHP Code:

    $result 
    mysql_query("SELECT * FROM movie WHERE title LIKE $_REQUEST['search'] ORDER by title DESC");

    if (
    $record mysql_fetch_array($result)) {
        do {
            echo 
    $record['title'] . "<br>\n";
        } while (
    $record mysql_fetch_array($result));
    } else {
        echo 
    "No records found!";

    I'm trying to use the code above but it doesn't work, so what is wrong? I have a submit button that posts to this script and a textbox called search. So when i hit submit it should post the contents of search to this script then the script displays the records which match the query.

    what is wrong with my code?


    Also I have a combo box with different colums that i can search by. How can i have it so when the info is posted, the text in the combo box called cats is posted and then depending on what is in the combo box it changes the query?

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    PHP Code:
    $result mysql_query("SELECT * FROM movie WHERE title LIKE '%".$_REQUEST['search']."%' ORDER by title DESC");

    if (
    $record mysql_fetch_array($result)) {
        do {
            echo 
    $record['title'] . "<br>\n";
        } while (
    $record mysql_fetch_array($result));
    } else {
        echo 
    "No records found!";

    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    thanks, do u happen to know how to do the second part?

    like i have a combo box caled cats with the following in it: Title, Date, Author

    Now when i his search if the combo box says Title it does this query:

    "SELECT * FROM movie WHERE title LIKE '%".$_REQUEST['search']."%' ORDER by title DESC"

    if it says Date it does this query:

    "SELECT * FROM movie WHERE date LIKE '%".$_REQUEST['search']."%' ORDER by title DESC"

    and if it says author it does this query:

    "SELECT * FROM movie WHERE author LIKE '%".$_REQUEST['search']."%' ORDER by title DESC"

    How would i get the script to choose the right query based on $_REQUEST['cats']

    ?

  4. #4
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    This should be your combo box:
    Code:
    <select name="cats" size="1">
      <option value="title">Title</option>
      <option value="date">Date</option>
      <option value="author">Author</option>
    </select>

    Your PHP Code:
    PHP Code:
    $result mysql_query("SELECT * FROM movie WHERE ".$_REQUEST['cats']." LIKE '%".$_REQUEST['search']."%' ORDER by title DESC");

    if (
    $record mysql_fetch_array($result)) {
        do {
            echo 
    $record['title'] . "<br>\n";
        } while (
    $record mysql_fetch_array($result));
    } else {
        echo 
    "No records found!";

    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  5. #5

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    thanks a bunch

Posting Permissions

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



Click Here to Expand Forum to Full Width