Re: Can a range be passed to a query?
| From: | Paul M Foster | Date: | Sat, 01 Aug 2009 05:06:36 +0000 |
| Subject: | Re: Can a range be passed to a query? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-296154@lists.php.net to get a copy of this message | ||
(Sorry, forgot to send this to the whole list.)
On Fri, Jul 31, 2009 at 05:24:45PM -0400, Miller, Terion wrote:
> I'm still struggling with using ranges... Can they be passed to a query
> somehow...
>
> I have this so far but it pulls nothing:
>
> //Show all with $letter not between "A" and "Z"
>
> if ($selectedLetter = "#") {
Problem #1: The above expression will set $selectedLetter to '#', *not*
check whether $selectedLetter is equal to '#'.
>
> $other = range('0','9');
>
> $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE
> '$other'";
Problem #2: The range() function returns an array (see documentation).
Echo the $sql variable to screen and you may find that it says:
"SELECT DISTINCT ... LIKE 'Array'"
Try this:
$values = implode(',', $other);
$sql = "SELECT DISTINCT ... LIKE '$values'";
(See documentation for implode().)
<snip>
Paul
--
Paul M. Foster