0

I am calling my database to display on the page in a table. Currently i have a field called model where i list the different models of firearms. Ex. (Dt-11 Sporting, Dt-11 Sporting Left handed)

I am currently having a issue were it will not pull up all the requested info.

mysql_select_db("premiumguns") or die(mysql_error());
$make ='DT-11 Sporting';
if (isset($make)) {
$query = "SELECT Serial_No, Make, Model, Gauge, Barrel_Length, Price FROM PG_inv WHERE Model like '" . $make . "' ORDER BY PG_inv.Price";
}
else
{
$query = "SELECT Serial_No, Make, Model, Gauge, Barrel_Length, Price FROM PG_inv ORDER BY PG_inv.Price";
}

$result = mysql_query($query) or die(mysql_error())

As far as i am aware the Where Model like should pull all rows that have a model containing "DT-11 Sporting" Which should include the "Dt-11 Sporting Left Handed" described above. But when the page is loaded only fields containing exactly "DT-11 Sporting" are displayed. Am i missing something?

Thanks for your help in advance!

4

3 に答える 3

3

クエリにワイルドカードを入れなければ、= または like を使用しても問題ありません。

検索語の両側に % を追加したので、"blah blah Term blah blah" などの項目が検索されます。

$query = "SELECT Serial_No, Make, Model, Gauge, Barrel_Length, Price FROM PG_inv WHERE Model like '%" . $make . "%' ORDER BY PG_inv.Price";

LIKE "FOO"は = "FOO" と同じですwhere asLIKE "FOO%" は FOO で始まるすべてを言います

于 2013-07-29T20:48:30.773 に答える