if (isset($_GET['Country'])) {
if ($_GET['Country']) {
$nr = $db->query("SELECT count(*)from test WHERE Country = '$_GET[Country]'")->fetchColumn();
}
}
How would I go about preparing a statement like this where the value I am selecting is dynamic (As in user chosen)?
if ($stmt = $pdo->prepare('SELECT count(*) FROM test WHERE Country = :country')) { $stmt->execute(array(':country' => $_GET['Country'])); $count = $stmt->fetchAll(); }
Unless you mean dynamic userchosen as the properties to fetch, then the answer is no you cannot use binding for that (you cannot create a dynamic structure on a prepared statement).
if ($stmt = $pdo->prepare('SELECT count(*) FROM test WHERE Country = :country'))
{
$stmt->execute(array(':country' => $_GET['Country']));
$count = $stmt->fetchAll();
}
Unless you mean dynamic userchosen as the properties to fetch, then the answer is no you cannot use binding for that (you cannot create a dynamic structure on a prepared statement).
I mean the value in the Country field is user chosen.