0

I am populating a List in my application. In a different Activity I'm trying to get every "event" to display in a ListView. Therefore I set up a EditText where I enter a city e.g "Hamburg". After the confirm button is clicked the list is supposed to show all the events in Hamburg.

+---------+----------+----------+------------------+
| user_id |   name   | location |   description    |
+---------+----------+----------+------------------+
|       5 | Dinner   | Hamburg  | With the Family  |
|       6 | Marriage | Bremen   | Alex and Sabrina |
|       7 | Match    | Berlin   | Hamburg - Hertha |
|       8 | Meeting  | Berlin   | Alexanderplatz   |
|       9 | Cinema   | Berlin   | FUG2             |
+---------+----------+----------+------------------+

My question, I cannot figure out how to state the SQL-Statement in the PHP document. All i have is:

$result = mysql_query("SELECT * FROM events WHERE location = ':location'") or die(mysql_error());

enter image description here

vhu
  • 12,244
  • 11
  • 38
  • 48
Dominik
  • 31
  • 1
  • 5

3 Answers3

3

mysql_ functions are depricated. I don't think that original mysql extension supports named parameters. You really should look into mysqli or even better PDO.

In mysqli that would be something like:

$mysqli = new mysqli("localhost", "root", "password", "database");
$sql = "SELECT * FROM events WHERE location = ?";
$statement = $mysqli->prepare($sql);
$statement->bind_param("s", $location);
$statement->execute();
Bogdan Kuštan
  • 5,427
  • 1
  • 21
  • 30
0

If you are submitting data to php file then you can use something like this for location :

$location=$_POST['location'];
$result = mysql_query("SELECT * FROM events WHERE location = $location") or die(mysql_error());
pspatel
  • 508
  • 2
  • 7
  • 18
0
$result = mysql_query("SELECT * FROM events WHERE location = $location")
Saty
  • 22,443
  • 7
  • 33
  • 51