Re: [PHP-DB] SELECT LIKE with "%" and without "%"

[email protected] (Philip Thompson)
Newsgroups php.db
Message-ID <[email protected]>
On May 2, 2009, at 6:43 PM, Emiliano Boragina wrote:

> Hello.
>
> I am using this:
> $sql = "SELECT * FROM table WHERE ID LIKE '%$_GET[id]%' AND title LIKE
> '%$_GET[word]%'";
>
> But I want exactlu ID, not one part of many possibles Ids in the DB.
> How can I do that?

PLEASE tell me your cleaning that input...

http://php.net/mysql_real_escape_string

And to answer your question:

<?php
$id = mysql_real_escape_string ($_GET['id']);
$word = mysql_real_escape_string ($_GET['word']);

$sql = "SELECT * FROM `table` WHERE `ID` = '$id' AND `title` = '$word'";
?>

Read more on MySQL's "LIKE" functionality. Google can help you.

HTH,
~Philip
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.