ForEach Range Problems
am 31.07.2009 18:53:14 von tmiller
=20
I have this script that works, just a couple tweeks needed...
1. I don't want it to default to A being selected
2. I need the number range part to only display one # sign not 10 of them,
somehow I have to have it pull any record that does not start with alpha
$letter =3D
isset($_GET['letter']) ? $_GET['letter'] :"A";
=20
echo '
align=3D"center">';
=20
foreach(range('A','Z') as $c){
($letter == $=
c)
?
printf('%s ',$c)
: printf('
href=3D"browse.php?letter=3D%s">%s ',$c,$c);
}
=20
echo '
';
//Other
=20
=20
foreach(range('0','9') as $n){
($letter == $=
n)
?
printf('%s ',$n)
: printf('
href=3D"?letter=3D%s"># ',$n,$n);
}
=20
echo
"
";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 19:27:13 von Phpster
On Fri, Jul 31, 2009 at 12:53 PM, Miller,
Terion wrote:
>
>
>
>
> I have this script that works, just a couple tweeks needed...
>
> 1. I don't want it to default to A being selected
> 2. I need the number range part to only display one # sign not 10 of them=
,
> somehow I have to have it pull any record that does not start with alpha
>
>
> =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$letter =3D
> isset($_GET['letter']) ? $_GET['letter'] :"A";
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo '
> align=3D"center">';
>
> foreach(range('A','Z') as $c){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0($letter == $c)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0?
> printf('%s ',$c)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: printf('
> href=3D"browse.php?letter=3D%s">%s ',$c,$c);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo '
';
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Other
>
>
> foreach(range('0','9') as $n){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0($letter == $n)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0?
> printf('%s ',$n)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: printf('
> href=3D"?letter=3D%s"># ',$n,$n);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo
> "
";
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0?>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
How about
$letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
echo '
';
foreach(range('A','Z') as $c){
($letter == $c) ? printf('%s ',$c) : printf('
href=3D"browse.php?letter=3D%s">%s ',$c,$c);
}
echo '
';
//Other
$bNumberShown =3D false;
foreach(range('0','9') as $n){
if($letter == $n) {
printf('%s ',$n)
}else{
if ($bNumberShown){
printf(' ',$n,$n);
}else{
printf(' ',$n,$n);
$bNumberShown =3D true;
}
}
echo " ";
?>
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 19:40:04 von tmiller
On 7/31/09 12:27 PM, "Bastien Koert" wrote:
$letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
echo '';
foreach(range('A','Z') as $c){
($letter == $c) ? printf('%s ',$c) : printf('
href=3D"browse.php?letter=3D%s">%s ',$c,$c);
}
echo '
';
//Other
$bNumberShown =3D false;
foreach(range('0','9') as $n){
if($letter == $n) {
printf('%s ',$n)
}else{
if ($bNumberShown){
printf(' ',$n,$n);
}else{
printf(' ',$n,$n);
$bNumberShown =3D true;
}
}
echo " ";
Looks like it would work but I keep getting syntax error unexpected { at th=
e first
}else{
I have tried to move the brackets around but it just moves the error....
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 19:43:28 von Phpster
On Fri, Jul 31, 2009 at 1:40 PM, Miller,
Terion wrote:
>
>
>
> On 7/31/09 12:27 PM, "Bastien Koert" wrote:
>
> $letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
>
> =A0echo '';
>
> =A0foreach(range('A','Z') as $c){
> =A0 ($letter == $c) ? printf('%s ',$c) : printf('
> href=3D"browse.php?letter=3D%s">%s ',$c,$c);
> =A0}
>
> =A0echo '
';
>
> =A0//Other
> =A0$bNumberShown =3D false;
> =A0foreach(range('0','9') as $n){
> =A0 if($letter == $n) {
> =A0 =A0 printf('%s ',$n)
> =A0 }else{
> =A0 =A0if ($bNumberShown){
> =A0 =A0 =A0 printf(' ',$n,$n);
> =A0 =A0 }else{
> =A0 =A0 =A0 printf(' ',$n,$n);
> =A0 =A0 =A0 $bNumberShown =3D true;
> =A0 =A0 }
> =A0}
>
> =A0echo " ";
>
> Looks like it would work but I keep getting syntax error unexpected { at =
the first
> =A0}else{
> I have tried to move the brackets around but it just moves the error....
>
My bad, missed a closing curly brace on the foreach loop
$letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
echo '
';
foreach(range('A','Z') as $c){
($letter == $c) ? printf('%s ',$c) : printf('
href=3D"browse.php?letter=3D%s">%s ',$c,$c);
}
echo '
';
//Other
$bNumberShown =3D false;
foreach(range('0','9') as $n){
if($letter == $n) {
printf('%s ',$n)
}else{
if ($bNumberShown){
printf(' ',$n,$n);
}else{
printf(' ',$n,$n);
$bNumberShown =3D true;
}
}
}
echo " ";
?>
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 19:54:13 von tmiller
On 7/31/09 12:43 PM, "Bastien Koert" wrote:
On Fri, Jul 31, 2009 at 1:40 PM, Miller,
Terion wrote:
>
>
>
> On 7/31/09 12:27 PM, "Bastien Koert" wrote:
>
> $letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
>
> echo '';
>
> foreach(range('A','Z') as $c){
> ($letter == $c) ? printf('%s ',$c) : printf('
> href=3D"browse.php?letter=3D%s">%s ',$c,$c);
> }
>
> echo '
';
>
> //Other
> $bNumberShown =3D false;
> foreach(range('0','9') as $n){
> if($letter == $n) {
> printf('%s ',$n)
> }else{
> if ($bNumberShown){
> printf(' ',$n,$n);
> }else{
> printf(' ',$n,$n);
> $bNumberShown =3D true;
> }
> }
>
> echo " ";
>
> Looks like it would work but I keep getting syntax error unexpected { at =
the first
> }else{
> I have tried to move the brackets around but it just moves the error....
>
My bad, missed a closing curly brace on the foreach loop
$letter =3D isset($_GET['letter']) ? $_GET['letter'] :"";
echo '
';
foreach(range('A','Z') as $c){
($letter == $c) ? printf('%s ',$c) : printf('
href=3D"browse.php?letter=3D%s">%s ',$c,$c);
}
echo '
';
//Other
$bNumberShown =3D false;
foreach(range('0','9') as $n){
if($letter == $n) {
printf('%s ',$n)
}else{
if ($bNumberShown){
printf(' ',$n,$n);
}else{
printf(' ',$n,$n);
$bNumberShown =3D true;
}
}
}
echo " ";
?>
--
Bastien
Cat, the other other white meat
Argh still nothing just the blank page of death...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 20:14:48 von Shawn McKenzie
Miller, Terion wrote:
>
>
> On 7/31/09 12:43 PM, "Bastien Koert" wrote:
>
> On Fri, Jul 31, 2009 at 1:40 PM, Miller,
> Terion wrote:
>>
>>
>> On 7/31/09 12:27 PM, "Bastien Koert" wrote:
>>
>> $letter = isset($_GET['letter']) ? $_GET['letter'] :"";
>>
>> echo '';
>>
>> foreach(range('A','Z') as $c){
>> ($letter == $c) ? printf('%s ',$c) : printf('
>> href="browse.php?letter=%s">%s ',$c,$c);
>> }
>>
>> echo '
';
>>
>> //Other
>> $bNumberShown = false;
>> foreach(range('0','9') as $n){
>> if($letter == $n) {
>> printf('%s ',$n)
>> }else{
>> if ($bNumberShown){
>> printf(' ',$n,$n);
>> }else{
>> printf(' ',$n,$n);
>> $bNumberShown = true;
>> }
>> }
>>
>> echo " ";
>>
>> Looks like it would work but I keep getting syntax error unexpected { at the first
>> }else{
>> I have tried to move the brackets around but it just moves the error....
>>
>
> My bad, missed a closing curly brace on the foreach loop
>
>
> $letter = isset($_GET['letter']) ? $_GET['letter'] :"";
>
> echo '
';
>
> foreach(range('A','Z') as $c){
> ($letter == $c) ? printf('%s ',$c) : printf('
> href="browse.php?letter=%s">%s ',$c,$c);
> }
>
> echo '
';
>
> //Other
> $bNumberShown = false;
> foreach(range('0','9') as $n){
> if($letter == $n) {
> printf('%s ',$n)
> }else{
> if ($bNumberShown){
> printf(' ',$n,$n);
> }else{
> printf(' ',$n,$n);
> $bNumberShown = true;
> }
> }
> }
> echo " ";
>
> ?>
>
> --
>
> Bastien
>
> Cat, the other other white meat
>
> Argh still nothing just the blank page of death...
Maybe you need a ; after printf('%s ',$n).
Also, maybe you need an editor with a syntax highlighter? You and PJ
should get together and decide on one.
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 20:51:12 von tmiller
--snip---
--
Well I almost have it with this, I keep getting an undefined index $letter =
error though and then it outputs the $menu how do I fix that
//Create array with letters AND number sign $let=
ters =3D range('A','Z'); array_push($letters, '#')=
; $menu =3D ''; =
foreach($letters as $letter) { =
$menu .=3D ($letter == $_GET['letter']) =
? sprintf('%s ', $letter) : sprintf('<=
a href=3D"browse.php?letter=3D%s">%s ', $letter, $letter); =
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 20:56:55 von Phpster
On Fri, Jul 31, 2009 at 2:51 PM, Miller,
Terion wrote:
>
>
>
> --snip---
>
> --
> Well I almost have it with this, I keep getting an undefined index $lette=
r error though and then it outputs the $menu how do I fix that
>
> =A0//Create array with letters AND number sign =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0$letters =3D range('A','Z'); =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0array_push($letters, '#'); =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0$menu =3D ''; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0foreach($letters as $letter) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0$menu .=3D ($letter == $_GET['letter']) =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0? sprintf('%s ', $le=
tter) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: spri=
ntf(' ', $letter, $letter); =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>
What if you just add a
$letters =3D '';
at the top?
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 21:00:01 von tmiller
On 7/31/09 1:56 PM, "Bastien Koert" wrote:
$letters =3D '';
Nope still gives the same error: Notice: Undefined index: letter
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 21:10:40 von tmiller
On 7/31/09 2:00 PM, "Miller, Terion" wrote:
On 7/31/09 1:56 PM, "Bastien Koert" wrote:
$letters =3D '';
Nope still gives the same error: Notice: Undefined index: letter
Well getting closer with this but now my output menu is not a clickable lin=
k?
$letter =3D isset($_G=
ET['letter']) ? $_GET['letter'] :""; =
//Create array with letters AND number sign =
$letters =3D range('A','Z'); =
array_push($letters, '#'); =
$menu =3D ''; foreach($letters a=
s $letter) { $menu .=3D ($letter) =
? sprintf('%s', $letter) : sp=
rintf(' ', $letter, $letter); =
} =
echo "{$menu}
";
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 22:08:24 von Phpster
On Fri, Jul 31, 2009 at 3:10 PM, Miller,
Terion wrote:
>
>
>
> On 7/31/09 2:00 PM, "Miller, Terion" wrote=
:
>
>
>
>
> On 7/31/09 1:56 PM, "Bastien Koert" wrote:
>
> $letters =3D '';
>
> Nope still gives the same error: =A0Notice: Undefined index: letter
>
> Well getting closer with this but now my output menu is not a clickable l=
ink?
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$letter =3D isset($_GET['letter']) ? $_G=
ET['letter'] :""; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Create array with =
letters AND number sign =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $letters =3D range('A','Z'=
); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0array_push($letters, =
'#'); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$menu =3D ''; =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0foreach($letters as $letter) { =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$menu .=3D ($letter) =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0? sprintf('%s', $letter) =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0: sprintf('
ef=3D"browse.php?letter=3D%s">%s ', $letter, $letter); =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo=
"{$menu}
";
>
check the view source for the link to see what is happening to make it fail
--=20
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 22:10:07 von tmiller
On 7/31/09 3:08 PM, "Bastien Koert" wrote:
On Fri, Jul 31, 2009 at 3:10 PM, Miller,
Terion wrote:
>
>
>
> On 7/31/09 2:00 PM, "Miller, Terion" wrote=
:
>
>
>
>
> On 7/31/09 1:56 PM, "Bastien Koert" wrote:
>
> $letters =3D '';
>
> Nope still gives the same error: Notice: Undefined index: letter
>
> Well getting closer with this but now my output menu is not a clickable l=
ink?
>
> $letter =3D isset($_=
GET['letter']) ? $_GET['letter'] :""; =
//Create array with letters AND number sign =
$letters =3D range('A','Z'); =
array_push($letters, '#'); =
$menu =3D ''; foreach($letters =
as $letter) { $menu .=3D ($letter) =
? sprintf('%s', $letter) : s=
printf(' ', $letter, $letter);=
} =
echo "{$menu}
";
>
check the view source for the link to see what is happening to make it fail
--
Bastien
Cat, the other other white meat
I finally got it working pretty much..next I just have to apply it to the q=
uery so that if the user clicks the # it will pull the records that begin w=
ith a number instead of letter from the db...
On the home stretch...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 31.07.2009 22:51:26 von tmiller
-----snip-------
So I'm almost almost there, but now when I click the # it shows me all reco=
rds, is my foreach range not right?
//Create array with letters AND number sign $le=
tters =3D range('A','Z'); array_push($letters, '#');=
$menu =3D ''; =
$selectedLetter =3D isset($_GET['letter']) ? $_GET['letter'] : nu=
ll; foreach($letters as $letter) { =
$menu .=3D ($letter == $selectedLetter) =
? sprintf('%s ', $letter) : sprint=
f(' ', $letter, $letter); =
} echo "
{$menu}
=
"; =
=
//Show all restaurants that start with $letter n=
ot between "A" and "Z" =
$other =3D ctype_digit($letter); =
foreach(range('0','9') as $other) =
$sql =3D "SELECT DISTINCT ID, name, address=
FROM restaurants WHERE name LIKE '{$other}%' "; =
$result =3D mysql_query($sql) or die(mysql_er=
ror()); =
while($row =3D mysql_fetch_assoc($=
result)){ =
=
$name =3D $row['name']; =
printf( =
'
=3D%s">%s
%s
', =
$row['ID'], =
$row['name'], =
$row['address'] =
); =
=
} =
=
=
=
//Show all restaurants that start with $letter =
$sql =3D "SELECT DISTINCT ID, name, addres=
s FROM restaurants WHERE name LIKE '{$selectedLetter}%'"; =
$result =3D mysql_query($sql) or die(=
mysql_error()); =
while($row =3D mysql_fet=
ch_assoc($result)){ =
=
$name =3D $row['name']; =
printf( =
'
iew.php?ID=3D%s">%s
%s
', =
$row['ID'], =
$row['name'], =
$row['=
address'] );=
=
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ForEach Range Problems
am 01.08.2009 08:20:31 von Andrew Ballard
On Fri, Jul 31, 2009 at 4:51 PM, Miller,
Terion wrote:
> //Show all restaurants that start with $letter not
> between "A" and "Z"
>
> $other = ctype_digit($letter);
>
> foreach(range('0','9') as $other) {
>
> $sql = "SELECT DISTINCT ID, name, address
> FROM restaurants
> WHERE name LIKE '{$other}%' ";
>
> $result = mysql_query($sql) or die(mysql_error());
>
> while($row = mysql_fetch_assoc($result)){
>
> $name = $row['name'];
>
> printf(
> '%s
%s'
> . '
',
> $row['ID'],
> $row['name'],
> $row['address']
> );
> }
> }
Why are you running 10 individual queries to search for restaurants
whose name begins with a number?
There are (at least) two simple, sargable alternatives available that
will work in MySQL to do the work in one shot:
SELECT DISTINCT ID, name, address
FROM restaurants
WHERE name LIKE '0%'
OR name LIKE '1%'
OR name LIKE '2%'
OR name LIKE '3%'
OR name LIKE '4%'
OR name LIKE '5%'
OR name LIKE '6%'
OR name LIKE '7%'
OR name LIKE '8%'
OR name LIKE '9%'
(It can use an index on the `name` column and it works, but it's
pretty verbose. Performance might suffer a little if it involves a
table scan because of the OR's, but I'm not sure about that.)
SELECT DISTINCT ID, name, address
FROM restaurants
WHERE name >= '0' AND name < 'A';
(Its a lot shorter because it takes advantage of string collation. Any
string that begins with the character '0' will be greater than (or
equal if the string is exactly '0') than '0'.)
Also, if your table is set up correctly, you do not need the DISTINCT
keyword in your query. Each restaurant should appear exactly once in
the `restaurants` table.
And just for fun... do you have any restaurants in your list whose
name begins with a punctuation mark or some other non-alphanumeric
character? :-)
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php