1

(Duplicate marked) - has nothing to do with this... I am outputting an array of user data in to a HTML table (<tr>), and I am trying to impliment a search field, where you can search for a specific IP (WHERE IP LIKE ip). But I am having trouble adding this, as I only want it to search for WHERE IP LIKE ip when a search has actually been made. Right now, this iss how I tried to do it:

$users = $db->get ("user_data" . if(isset($_GET['ip'])) { echo "WHERE IP LIKE '$_GET[ip]'"} . "ORDER BY date DESC, time DESC LIMIT 10");

This gives me the error, "Parse error: syntax error, unexpected T_IF ... "

I have no clue what would be wrong with the code, other than it doesn't like me putting "if" where I put it... I am wanting to make a search for every single value (7), but so far it isn't going too well...

In the long run, I am working towards a result like this; http://namelessmc.com/members

Thank you in advance :)

Albert MN.
  • 713
  • 1
  • 16
  • 33

1 Answers1

0

Try like this.

$ip = "";
if(isset($_GET['ip']) && $_GET['ip']) { 
$ip = " WHERE IP LIKE '%".$_GET['ip']."%' ";
}
 $users = $db->get ("user_data" . $ip. " ORDER BY date DESC, time DESC LIMIT 10");

isset check for existence and you should also check for its value if you are sending variable ip in each request.

Drone
  • 1,114
  • 1
  • 12
  • 31