Hello everyone, looking for a little advice/help.

Heyas all, brand new to the forum, as well as PHP.

Reason for being here is that I could use some help to do something. Something that is beyond what I am currently capable of achieving.

The course is a CSS course and the assignment is to create a small page that uses some sort of ajax/php on it.

I have already done this part and feel comfortable that I have completed the assignment well enough to earn the maximum allowable points.

However, I would really like to add some functionality and fluff to the assignment while learning something during the process.

What I have is a HTML that when a user enters a letter into the box, calls a function that reads the array for possible matches. Such as entering the letter “D” in the box initially might pull up multiple names such as “Denise”,“Debbie”,“Donna”, etc…

What I would like to do is have those names appear as links if possible. So like if the user entered the name “Denise” they could then click on it. The destination, would not be very important, I am thinking perhaps just to the Wiki page concerning that name.

So, how would I go about doing this? Is that something coded into the html page? The php page? Some other manner. As I said, this is more fluff than anything else so I am by NO means asking anyone to do my homework for me. :slight_smile: I know how irritating and bothersome it must be for professionals, such as those who post help here, when someone comes looking for a free ride.

Here is the basic code as of now although I am not using this HTML file as is, only the function, which I will drop into my own pages code later. Thanks in advance! :smiley:

[php]<?php
// Fill up array with names
$a[]=“Anna”;
$a[]=“Brittany”;
$a[]=“Cinderella”;
$a[]=“Diana”;
$a[]=“Eva”;
$a[]=“Fiona”;
$a[]=“Gunda”;
$a[]=“Hege”;
$a[]=“Inga”;
$a[]=“Johanna”;
$a[]=“Kitty”;
$a[]=“Linda”;
$a[]=“Nina”;
$a[]=“Ophelia”;
$a[]=“Petunia”;
$a[]=“Amanda”;
$a[]=“Raquel”;
$a[]=“Cindy”;
$a[]=“Doris”;
$a[]=“Eve”;
$a[]=“Evita”;
$a[]=“Sunniva”;
$a[]=“Tove”;
$a[]=“Unni”;
$a[]=“Tasha http://en.wikipedia.org/wiki/Tasha_Yar”;
$a[]=“Liza”;
$a[]=“Elizabeth”;
$a[]=“Ellen”;
$a[]=“Wenche”;
$a[]=“Vicky”;

//get the q parameter from URL
$q=$_GET[“q”];

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}

// Set output to “no suggestion” if no hint were found
// or to the correct values
if ($hint == “”)
{
$response=“no suggestion”;
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>[/php]

[code]

Start typing a name in the input field below:

First name:

Suggestions:

[/code]

Right now the PHP script you call from the Javascript replies with only the name. If you change that script to reply with <a href="#your link goes here#" target="#if you need that#">The Name</a> you get a link. ( Of course you’ll have to ut a valid link and target inthere )

Does that help?
:wink:

If you are asking how to do the search, I would do a for clause and check the first letter.
When found, create the link using the actual data. You would use something like this to call Wickie…

$subject = whatever you need to pull the name from your array…
echo “<a href=‘http://en.wikipedia.org/wiki/’” . $subject . “’>” . $subject . “”;

Note: the above has double-quotes for PHP code and single-quotes for the ones around html values…
(Some programmers don’t see that…) And, this version is for Wiki-ENGLISH…

Hope that helps some…

Sponsor our Newsletter | Privacy Policy | Terms of Service