function to search all fields in a mysql table

Discussion in 'PHP' started by klown, Feb 7, 2007.

  1. #1
    I'm just wondering if anybody already has this done.. Basically it should check all find all the fields in a table for LIKE %...%

    To do this it needs to detect each of the fields then make a mysql query with a bunch of 'OR's.. Anyhow greens to anybody who pastes it in here..
     
    klown, Feb 7, 2007 IP
  2. technoguy

    technoguy Notable Member

    Messages:
    4,387
    Likes Received:
    308
    Best Answers:
    0
    Trophy Points:
    205
    #2
    Try this

    
    $conn = @mysql_connect( 'localhost',$uname ,$pass)
            or die( mysql_errno().': '.mysql_error().NL );
    $db=mysql_select_db($db,$conn);
    $result = mysql_query("SHOW COLUMNS FROM $table");
    
    if (mysql_num_rows($result) > 0) 
    {
    $i=0;
      while ($row = mysql_fetch_array($result)) 
       {
    if($i==0)
    {
     
    	$q="select * from $table where ".$row[0]."=".$condition;
    }
    else
    {
    $q.=" or ".$row[0]."=".$condition;
    }
    $i++;
    }
    }
    
    echo $q;
    
    
    PHP:
     
    technoguy, Feb 7, 2007 IP
    klown likes this.
  3. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That works perfectly, thanks
     
    klown, Feb 7, 2007 IP
  4. technoguy

    technoguy Notable Member

    Messages:
    4,387
    Likes Received:
    308
    Best Answers:
    0
    Trophy Points:
    205
    #4
    you are requested to give rep. If you have any problem you can contact me.
     
    technoguy, Feb 7, 2007 IP
  5. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Gave you rep before i even posted my reply there ;)
     
    klown, Feb 7, 2007 IP
  6. thangtkt

    thangtkt Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    how can find ways to interrupt
    example :
    text: one two three
    search : one three
     
    thangtkt, Nov 28, 2015 IP