Ajax autocomplete searchbox und php array problem

Gesperrt
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Ajax autocomplete searchbox und php array problem

Beitrag von djavet »

Hello

I'm workin a ajax search box (my first module for 4.6.8 for the community) with a visible/hidden field with keywords. With a static array, it's work perfect, but when I try to make the same with a recordset I receive a error.
Bild

I wish convert my variable "$keywords" into a array like this:
$liste = array("abeille","abricot","acheter","acheteur","zèbre","zéro");

I try to do so:
$liste = $keywords;

But I receive a error:
Warning : Invalid argument supplied for foreach() in c:\documents and settings\web1\my documents\www\ajax\autocomplete\options.php on line 21.

Line 21 are:
foreach ($liste as $element) {

What is wrong?

A lot of thx for your help and time.

Regards,
Dominique


My php code:

Code: Alles auswählen

<?php include '../Connections/connect.php';

mysql_select_db($database_connect, $connect);
$keywords = "SELECT artist_name FROM artists";

header('Content-Type: text/xml;charset=utf-8');
echo(utf8_encode("<?xml version='1.0' encoding='UTF-8' ?><options>"));
if (isset($_GET['debut'])) {
    $debut = utf8_decode($_GET['debut']);
} else {
    $debut = "";
}
$debut = strtolower($debut);

//$liste = $keywords;
$liste = array("abeille","abricot","acheter","voisin","voisinage","vouloir","voyage","voyageur","zèbre","zéro");

function generateOptions($debut,$liste) {
    $MAX_RETURN = 10;
    $i = 0;
    foreach ($liste as $element) {
        if ($i<$MAX_RETURN && substr($element, 0, strlen($debut))==$debut) {
            echo(utf8_encode("<option>".$element."</option>"));
            $i++;
        }
    }
}

generateOptions($debut,$liste);

echo("</options>");
?>
i-fekt
Beiträge: 1520
Registriert: Mo 3. Jan 2005, 02:15
Wohnort: Chemnitz
Kontaktdaten:

Beitrag von i-fekt »

Please submit the whole module.
Gruss,
Michael

"Keep on riding this Bike!" (Jackson Mulham)
stese
Beiträge: 1040
Registriert: Fr 3. Dez 2004, 17:47
Wohnort: München
Kontaktdaten:

Beitrag von stese »

it seems that your variable $keywords is not an array. is it possible, that the variable is a comma seperated value?

please show us the code where you fill the $keywords variable.
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

It isn't:

Code: Alles auswählen

$keywords = "SELECT artist_name FROM artists";
In general: Is it the same database? Than you should use the DB_Contenido object.

Everything else about getting the values from the database is missing some imprtant parts:
Change this

Code: Alles auswählen

$keywords = "SELECT artist_name FROM artists";
to

Code: Alles auswählen

$sql = "SELECT artist_name FROM artists";
// There should be a query...
$result = mysql_query($sql, $connect);
// And the result should be stored in your variable
$liste = array();
while ($row = mysql_fetch_assoc($result)) {
   $liste[] = $row["artist_name"];
}
Note, that this can only work, if the included script specifies $connect as link to a database...

Also, as you are getting the results from the database, you could replace the function just by using the while construct and putting the code from the function into the while loop...

See http://www.php.net about a documentation and many, many examples...

Regards,
HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

Thx!

Here it's a zip with the whole script:
http://www.metadelic.com/upload/autocomplete_mysql.zip

I've just uncomment in "option.php", line 23 the $list variable.
I've the xml file, doesn't work with my form.

It's very static and only experiment and this time not include in Contenido synthax. So excuse me. I'm not a php/ajax expert. I learn.

Regards, Dom
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

You said, the static version is running.

If I understand anything correctly, you'd like to get the database version running. Is the table in the same database as Contenido?

Regards,

HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

Hi

Thx for your reply. No the table are not for this test the same as Contenido. This will come later. I've made a simple table to understand the process.

Any idea?

Regards, Dom
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

Sure, move the table to the Contenido database and we will get you up and running in no time.

Regards,

HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

Hi!

I've move the table to contenido:
http://web92.ypsilon.ibone.ch/upload/autocomplete.zip

And the dynamic example:
http://web92.ypsilon.ibone.ch/cms/autocomplete/

But it doesn't work.
when I add the config file for the connection for my query, it stop working...

Regards, Dom
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

I didn't say, that it will work from scratch - there is still coding to do. I will take a look in the evening.

Regards,
HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

Hi

I understand what you're saying. I'm still learning. Thx for your help.
I think it maybe a confusion with the variable name.

Regards, Dom
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

HerrB hat geschrieben:I didn't say, that it will work from scratch - there is still coding to do. I will take a look in the evening.

Regards,
HerrB
Hi!

Do you have find something?

Regards, Dominique
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

Err, to tell the truth: no, sorry. I won't today, Monday, Tuesday, Wednesday perhaps. Pease send me a PM as reminder.

Regards,

HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
Gesperrt