-2

if i use this link it is working fine search.php?search=ali&city=dubai&submit=Search

but if i use this no result found search.php?search=ali&city=0&submit=Search

I have three rows in data table

  • 1st is name
  • 2nd is city
  • 3rd is date

if i search name with city it is showing result but when i search only name then no result found i want both type of result.

how can i fix this isuuse thanks in advance

$getquery = mysql_query("SELECT * FROM data WHERE $construct  AND  city='$city' ORDER BY DATE DESC LIMIT $start, $per_page");
  • Show us your code, please. – Darwin von Corax Dec 30 '15 at 18:27
  • 2
    RTM on `WHERE` http://dev.mysql.com/doc/refman/5.7/en/where-optimizations.html and add `or die(mysql_error())` to `mysql_query()` and you will see the syntax error you are probably making, since we have NO idea what your `$construct` does. – Funk Forty Niner Dec 30 '15 at 18:30
  • 1
    Is it really worth mentioning the [deprecated 'thing' about mysql_* functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and [sql injection vulnerability](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)? What do you think @Fred-ii-? I see you around php a lot and this uses keep coming. I don't know if I should keep repeating myself about this... – FirstOne Dec 30 '15 at 18:39
  • 3
    Your questions is **unanswerable** in its present state and for many reasons. Which MySQL API used to connect with, where those variables are assigned as, and the list goes on. ***"You"*** have to learn how to ***"debug"*** your code; that isn't our job, it's yours. – Funk Forty Niner Dec 30 '15 at 18:40
  • 2
    @FirstOne Given the OP's track record and questions asked, I wouldn't waste my breath. – Funk Forty Niner Dec 30 '15 at 18:41

1 Answers1

0

Here you go. Remove the City condition where clause as show below.

$getquery = mysql_query("SELECT * FROM data WHERE $construct 
ORDER BY DATE DESC LIMIT $start, $per_page");

Then set the value of $construct according to data availability.

If only "Name" is available in query string, then set $construct as Name=$search

if both name and city is available, then set $construct as Name=$search and city=$city

cyber.sh
  • 712
  • 4
  • 10
  • 2
    I'll repost my comment I left in the "now deleted answer": I wouldn't move so fast with this. Not without knowing what their `$construct` does exactly, and wasn't posted. – Funk Forty Niner Dec 30 '15 at 18:35