0

could anyone provide code for me how to search data using column name.

example: if i have 2 columns called NAME,ID then i select NAME or ID and enter the keyword to search.
would greatly appreciate your help!

Edited by mtvaran: n/a

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by mtvaran
0

Simply you can do this with a simple if/elseif/else statement.
You just have to play with your variables and with your database fields.

<?php
    
    if (isset($_REQUEST['yourColumnValue1']) && $_REQUEST['yourColumnValue1'])
    {    
        $q = mysql_query("SELECT * FROM yourTable 
                          WHERE yourField LIKE '%".mysql_real_escape_string($_REQUEST['SearchValue'])."%' 
                          || yourField2 = '".mysql_real_escape_string($_REQUEST['SearchValue'])."' 
                          ORDER BY x, y");
    }
    elseif (isset($_REQUEST['yourColumnValue2']) && $_REQUEST['yourColumnValue2'])
    {    
        $q = mysql_query("SELECT * FROM yourTable 
                          WHERE yourField LIKE '%".mysql_real_escape_string($_REQUEST['SearchValue'])."%' 
                          || yourField2 = '".mysql_real_escape_string($_REQUEST['SearchValue'])."' 
                          ORDER BY x, y");
    }
    
    
?>

Edited by Szabi Zsoldos: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.