$query = "select ID where student='Roger'";
if ($address > 5) {
$query .= "and Address='$address'";
}
You'll also probably need to use the DBI module to access your database. If you're using mysql:
#first connect to the database
$c_dsn = 'DBI:mysql:database=' . $database;
$c_dsn = $c_dsn . ';host=' . $host;
$c_dsn = $c_dsn . ';port=' . $port;
$db_conn = DBI->connect($c_dsn, $username, $password);
#now execute the query
$executing = $db_conn->prepare($query);
$db_ref = $executing->execute();
#read information
while (@res = $db_ref->fetchrow_array) {
#do something with the result array
for $res(@res) {
print $res . "\n";
}
}
Hope this helps.