/    Sign up×
Community /Pin to ProfileBookmark

Can someone try rewriting this for php4?

the code is from: [url]http://nodstrum.com/2007/09/19/autocompleter/[/url]

[code=html]

if(isset($_POST[‘queryString’]))
{
$queryString = $_POST[‘queryString’];

if(strlen($queryString) >0) {

$query = $db->query(“SELECT value FROM countries WHERE value LIKE ‘$queryString%’ LIMIT 10”);
if($query) {

while ($result = $query ->fetch_object()) {

echo ‘<li onclick=”fill(’‘.$result->value.’‘);”>’.$result->value.‘</li>’;
}
}
else {
echo ‘ERROR: There was a problem with the query.’;
}
}
else {

}
} else {
echo ‘There should be no direct access to this script!’;
}
}

?>[/code]

i guess i just don’t know how to convert
echo ‘<li onclick=”fill(’‘.$result->value.’‘);”>’.$result->value.‘</li>’;
into php4, without getting some errors along the way. thank you in advance

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@sushiJun 27.2008 — dont' fetch an object from the database. Fetch an array and use

[code=php]

echo ‘<li onclick="fill(’‘.$result['value'].’‘);">’.$result['value'].‘</li>’;


[/code]
Copy linkTweet thisAlerts:
@xpiamchrisauthorJun 27.2008 — dont' fetch an object from the database. Fetch an array and use

[code=php]

echo ‘<li onclick="fill(’‘.$result['value'].’‘);">’.$result['value'].‘</li>’;


[/code]
[/QUOTE]



So how does this look?

and i don't understand why double quotes are used outside of the

' '.$result['value']. ' ;'

[code=html]if(isset($_POST['queryString']))
{

$queryString = $_POST['queryString'];

if(strlen($queryString) >0)

{

$result = mysql_query("SELECT buddy FROM contacts WHERE buddy LIKE '$queryString%' LIMIT 10");

if($result)
{
//fetch rows from result set.

while ($row = mysql_fetch_array($result))
{
$buddy= $row['buddy'];
echo '<li onclick="fill('.$row['buddy'].');">' .$row['buddy'].'</li>';


}

}

else
{
echo 'ERROR: There was a problem with the query.';
}

}
else
{

} // There is a queryString.

}
else
{
echo 'There should be no direct access to this script!';
}

?>[/code]
Copy linkTweet thisAlerts:
@felgallJun 27.2008 — The " are a part of the HTML being created.
Copy linkTweet thisAlerts:
@xpiamchrisauthorJun 27.2008 — so what's wrong with this code... if any?
[CODE]if(isset($_POST['queryString']))
{

$queryString = $_POST['queryString'];

if(strlen($queryString) >0)
{
$result = mysql_query("SELECT buddy FROM contacts WHERE buddy LIKE '$queryString%' LIMIT 10");

if($result)
{
//fetch rows from result set.
while ($row = mysql_fetch_array($result))
{
echo '<li onclick="fill('.$row['buddy'].');">' .$row['buddy'].'</li>';
}
}

else
{
echo 'ERROR: There was a problem with the query.';
}

}
else
{

} // There is a queryString.

}
else
{
echo 'There should be no direct access to this script!';
}[/CODE]
Copy linkTweet thisAlerts:
@mrizwanJun 27.2008 — Use this code
echo "<li onclick='fill(" . $row['buddy'] . ");>" . $row['buddy'] . "</li>";[/QUOTE]
Copy linkTweet thisAlerts:
@xpiamchrisauthorJun 27.2008 — Use this code[/QUOTE]

still produces the same error...(btw, i think you were missing a single quote to finish off the fill)

i think ive narrowed the problem down. in a working autocomplete call, this is what gets outputted:

<li onClick="fill('Chicago');">Chicago</li>

however, mine (according to firebug) outputs

<li onClick="fill(Chicago);">Vanuatu</li>

so the single quotes around the text in the fill parenthesis are missing...

any answers?

(thanks so far for the support.)
Copy linkTweet thisAlerts:
@muingboySep 10.2008 — Hi,

In relation to the code described above.....does anybody know what changes I need to make to

echo '<li onClick="fill(''.$result->Name.'');">'.$result->Name.'</li>';


so that it will handle names with " ' " such as john's or Boston's etc ?

Thanks

Al
×

Success!

Help @xpiamchris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...