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!
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!
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");
}
?>
There seems to be a lot of code duplication here. Also use POST or GET as opposed to REQUEST.
thanks guys.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.