Вопрос

I need make a search in php and oci using just prefixes of the terms, for example:

if the user type bud the result must contains all rows on the database that contains bud as part of the name. For exact terms my search is ok with the function:

function get_station_by_name($conn, $name, $skip = 0, $maxrows = -1){
    $statement = db_create_statement($conn, "SELECT id, name, city, avg_pass, min_pass FROM station WHERE name = :name");
    db_bind($statement, ':name', $name);
    return db_fetch_resultset($statement, $skip, $maxrows);
}

function db_bind($statement, $name, $value) {
    return oci_bind_by_name($statement, $name, $value);
}

I've search a lot how to do that, but I could not find very well results. I think I must include in my $name variable symbols like %,*.

Thank you very much

Это было полезно?

Решение

$name = "bud";
$statement = "SELECT id, name, city, avg_pass, min_pass FROM station WHERE name LIKE :name";
db_bind($statement, ':name', "%" . $name . "%");

Looks for stations where the name contains "bud" E.g buddingham or debudding

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top