search a particular text in table..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    search a particular text in table..?

    hai experts,
    for example my table name is employee with two columns id,name and description.[HTML]<body><table><t r><td><b>id</b></td><td><b>name</b></td><td><b>descr iption</b></td></tr><tr><td>123</td><td>shankar</td><td>gentlema n</td></tr><tr><td>345</td><td>gavaskar </td><td>cricket</td></tr><tr><td>347</td><td>sachin</td><td>cricket</td></tr></table></body>[/HTML]
    if i enter 'KAR' and click the search button , i need the result as
    123 shankar gentleman
    345 gavaskar cricket
    by searching the word 'kar' in name column.
    if i enter 'cricket' and click the search button , i need the result as
    345 gavaskar cricket
    347 sachin cricket
    what should i do....?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I hope you are talking about a MySQL table, because what you showed in your post is a html table. But since this is the MySQL forum:

    [php]
    $sql = "SELECT name, description FROM table ".
    " WHERE name REGEXP '$searchword' ".
    " OR description REGEXP '$searchword' ".
    " ORDER BY categorie ";

    $conn = mysql_connect(S QL_HOST, SQL_USER, SQL_PASS)
    or die("Connect error: ".mysql_error() );

    mysql_select_db (SQL_DB)
    or die("DB select error: ".mysql_error() );

    $res = mysql_query($sq l)
    or die("SQL select error: ".mysql_error() );

    if (mysql_num_rows ($res) < 1)
    echo 'no rsults found';

    else {
    // show your data
    }[/php]

    Ronald :cool:

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      yah! iam talking about mysql table only. i think that this html table coding will show the user in table format. sorry..
      i need a mysql query for the corresponding table format.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        But this is a MySQL search query!!

        You ask for a table search and you post a thread in the MySQL forum!! So what do you think it is??

        Code:
         $sql  = "SELECT name, description FROM table ".
                " WHERE name REGEXP '$searchword' ".
                " OR description REGEXP '$searchword' ".
                " ORDER BY categorie ";
        Ronald :cool:

        Comment

        Working...