TABLE bcompany
companyID | cName | ...
I have the input field, where user searches for the records including the “input” characters:
<input type="text" class="bigblack" name="srch" />
PHP:
$req="%".mysql_real_escape_string($_POST['srch'])."%";
$query = mysql_query("SELECT companyID, cName FROM bcompany WHERE
companyID OR cName LIKE $req ORDER BY companyID LIMIT 10");
OR
$query = mysql_query("SELECT companyID, cName FROM bcompany WHERE
companyID,cName LIKE $req ORDER BY companyID LIMIT 10");
Both queries return an error:
mysql_fetch_array() expects parameter 1 to be resource….
There is probably something wrong with the MYSQL SELECT.
Can you please help me solve this out?
Thanks in advance 🙂
Rest of the code:
while($res = mysql_fetch_array($query)) {
echo $res["companyID"];
echo $res["cName"]."<br>";
}
You query should be:
Here are the docs for MySQL LIKE:
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
Alternatively you could use the MySQL REGEXP in place of LIKE in your queries.
It looks like mysql_fetch_array is griping when you call it because the query is incorrect and not producing a result which mysql_fetch_array can use.