1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    first of all i want to sorry about my bad english.
    how do i make php script for searching in mysql database ?
    i want to make a student search..
    the field is student_number, name, address, and faculty.
    what would the php script look like ?

  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    I'm not too clear on the details of what you're asking, but the script might look something like this.

    First we need to define the query we'll be using:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if($student_id){$searchResult=mysql_query("select * from tableName where student_id='$student_id'");}
    elseif($name){$searchResult=mysql_query("select * from tableName where name like '%$name%'");}
    elseif($address){$searchResult=mysql_query("select * from ...

    Then you need to read the information out:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    echo "ID: $student[student_id]<br>";
    echo "Name: $student[name]<br>";
    echo "Address: $student[address]<br>";
    echo "Faculty: $student[faculty]<br><br>";

    That may not be exactly what you want, but I hope it helps....
  4. #3
  5. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    This is kind of on the same topic:

    How do you cut up or format the variable before it the search begins?
    For example, if the datebase has the student name as 'Steve Smith', but the user enters 'Smith, Steve' how can I split this string and search the whole database for all occurences of steve and smith?
  6. #4
  7. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    If the bits are always going to be delimited by a comma, then one can split the string by the comma and then -

    $command = "select * from table where
    name like '%$name1%' or
    name like '%name2%';";

    then mysql_db_query.. etc.


    [This message has been edited by chyrag (edited 07-27-99).]
  8. #5
  9. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    What if there isn't a comma? What you have no control over how they enter it? How do you just dice up the string into individual complete words?
  10. #6
  11. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    There might be a function that will splice a string into each individual word. I'm not sure but explode comes to mind.

    Or, you would have to develop a script that will read each character and build a word letter by letter and when a comma or space appears use it as a marker that the word ended.

    Hope this helps.

Similar Threads

  1. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 03:39 AM
  2. search engine project
    By mahnaz in forum Project Help Wanted
    Replies: 0
    Last Post: February 10th, 2004, 08:15 AM
  3. iframes that are orphaned by search engine.
    By junpei in forum HTML Programming
    Replies: 2
    Last Post: February 6th, 2004, 12:15 PM
  4. search my products database
    By SeenGee in forum PHP Development
    Replies: 9
    Last Post: February 5th, 2004, 05:00 PM
  5. Replies: 1
    Last Post: January 12th, 2004, 04:01 AM

IMN logo majestic logo threadwatch logo seochat tools logo