0

enter image description here

I want to match a value from multiple columns of a table .but when i execute my code it returns the error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\srctravellers\php\searchbustiming.php on line 15

My code is :

$tocity=$_POST['tocity'];
$res=mysql_query("SELECT  Route FROM routes where $tocity IN('City1','City2','City3','City4','City5','City6','City7','City8','City9','City10')");
while($result=mysql_fetch_array($res)){
    echo $result['Route'];
}

Here is snapshot of my columns of my table

Murad Hasan
  • 9,418
  • 2
  • 19
  • 40
irfan spi
  • 68
  • 2
  • 13

2 Answers2

0

when a mysql query fails it returns false so your '$res' variable contains false thats why you get boolean given.You can get the reason of failure for your query by using mysql_error() and then you can handle it accordingly.

Shahrukh
  • 102
  • 5
0

You have to use LIKE Operator here.

Query

$tocity=$_POST['tocity'];
$res=mysql_query("SELECT  Route FROM routes where City1 LIKE '%$tocity%' OR City2 LIKE '%$tocity%' OR City3 LIKE '%$tocity%' OR City4 LIKE '%$tocity%' OR City5 LIKE '%$tocity%' OR City6 LIKE '%$tocity%' OR City7 LIKE '%$tocity%' OR City8 LIKE '%$tocity%' OR City9 LIKE '%$tocity%' OR City10 LIKE '%$tocity%' OR )");
while($result=mysql_fetch_array($res)){
    echo $result['Route'];
}
Murad Hasan
  • 9,418
  • 2
  • 19
  • 40