Frank Rocco
|
| Posted: 07/08/2002, 1:49 PM |
|
Hello,
I need to compare the first 3 digits in a integer field in mySQL database.
I coded select * from db where left(fld1,3) = '123'
This fails because fld1 is numeric.
What is the correct syntax in PHP?
Thanks
Frank
|
|
|
 |
Chris Seymour
|
| Posted: 07/09/2002, 11:14 AM |
|
Hi Frank,
I have not tried this yet (I will when I get a minute),
but would this work:
select * from db where left(fld1,3) = 123
Just a thought.
Chris
|
|
|
 |
Alistair McFadyen
|
| Posted: 07/10/2002, 1:14 AM |
|
Hi Frank
I think the php substr() function may be the one you are looking for:
$numberval=1234;
$stringval = strval($numberval);
$stringval = substr($stringval,0,3);
echo $stringval;
The above returns "123", allowing you to pass $stringval into your query.
Hoipe this helps
Alistair McFadyen
"Frank Rocco" <farocco@hotmail.com> wrote in message
news:agcttk$gv6$1@news.codecharge.com...
> Hello,
>
> I need to compare the first 3 digits in a integer field in mySQL database.
> I coded select * from db where left(fld1,3) = '123'
>
> This fails because fld1 is numeric.
>
> What is the correct syntax in PHP?
>
> Thanks
>
> Frank
>
>
|
|
|
 |
Frank Rocco
|
| Posted: 07/15/2002, 9:47 AM |
|
Thanks for the help.
I also did not realize that in PHP, strings are 0 based. Seeing as it is
close to C, should have caught that earlier.
Regards,
Frank
|
|
|
 |
|