I am trying to create a clone of Google Suggest for my website. I am trying to use the code from w3schools.com to make it.
The tutorial gives details in ASP which I am not very familiar with. My PHP is a little sketcy but I have done my best to try and convert the ASP to PHP but I am stuck was wondering whether there was anyone who could help me?
I have got the XHTML, CSS and Javascript sussed but I cant quite seem to manage this!
I think it's mostly getting the syntax for the while and if statements right but I could be wrong.
Thanks in advance,
Darryl
ASP
Code: Select all
dim a(30)
a(1)="Anna"
a(2)="Brittany"
a(3)="Cinderella"
a(4)="Diana"
a(5)="Eva"
q=request.querystring("q")
if len(q)>0 then
hint=""
for i=1 to 30
x1=ucase(mid(q,1,len(q)))
x2=ucase(mid(a(i),1,len(q)))
if x1=x2 then
if hint="" then
hint=a(i)
else
hint=hint & " , " & a(i)
end if
end if
next
end if
if hint="" then
response.write("no suggestion")
else
response.write(hint)
end ifCode: Select all
<?php $a = array('Fred', 'Bob', 'Bill'); ?>
<?php $q = $_GET['q'] ?>
<?php
$i = '0';
echo $hint;
if (strlen($q) > 0)
while( $i <= count($a))
{
echo $a[$i];
$x1 = strtoupper(substr($q,'1',strlen($q)));
$x2 = strtoupper(substr($a[$i],'1',strlen($q)));
if ($x1 = $x2)
$hint = $hint && $a[$i];
echo $hint;
else
echo $hint;
$i++;
}
else
$hint = '';