Re: More: Frustrating ?
| From: | CC Zona | Date: | Mon, 18 Feb 2002 07:10:05 +0000 |
| Subject: | Re: More: Frustrating ? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-85165@lists.php.net to get a copy of this message | ||
In article <3C70A662.DB9F84E@collegesherbrooke.qc.ca>,
taylorjo@collegesherbrooke.qc.ca (Jtjohnston) wrote:
> > > $where = "id like $id";
<snip>
> So I do?
>
> $news = mysql_query("select * from ccl where '.$where.' order by AU desc");
>
> or ?
>
> $news = mysql_query("select * from ccl where '.%$where%.' order by AU
> desc");
Neither. Where $id==1, these would interpolate to:
select * from ccl where '.id like 1.' order by AU desc
select * from ccl where '.%id like 1%.' order by AU desc
This is why <repeat>error checking with an echo of your query to the
browser</repeat> is valuable. You can see exactly what the complete query
string looks like, and also copy/paste it to the commandline for further
testing.
> The % are not necessary? because id is an auto_increment number from 0 to
> 1,000+.
The "like" keyword is used with a wildcard operator, either "%" or
"_". If
you're matching against an exact value, then use the "=" operator instead
of "like". See the MySQL manual for more info on the "like" keyword and
wildcards.
If id has a numerical field type instead of one of the string types, you
don't need to quote $id. See the MySQL manual for more info on quoting
string values.
--
CC