I’m try include this plugin on my site, it’s working fine but I am having some problems with PHP.
When I write the PHP like this:
$default_tags = 'Avanture, Giorgio, Armani, Depeche, Mode, Pevanje, Francuska, usluživanje, Pravo, Menadžer, prodaje, Advokat';
if (!@$_SESSION['existing_tags']) {
$_SESSION['existing_tags'] = $default_tags;
}
$existing_tags = $_SESSION['existing_tags'];
$tags = split(' ', $default_tags);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && @$_GET['tag']) {
$match = array();
foreach ($tags as $tag) {
if (stripos($tag, $_GET['tag']) === 0) {
$match[] = $tag;
}
}
echo json_encode($match);
}
exit;
}
it works fine, but when I try to get a result from the database I have problems.
I have tried:
$query = mysql_query("SELECT * FROM tags");
while($row = mysql_fetch_array($query)) {
$default_tags = ''.$row['keyz'].', ';
if (!@$_SESSION['existing_tags']) {
$_SESSION['existing_tags'] = $default_tags;
}
$existing_tags = $_SESSION['existing_tags'];
$tags = split(' ', $default_tags);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && @$_GET['tag']) {
$match = array();
foreach ($tags as $tag) {
if (stripos($tag, $_GET['tag']) === 0) {
$match[] = $tag;
}
}
echo json_encode($match);
}
exit;
}
And this method is not working for me. Also, here is a screenshot from my database table tags. What is wrong with the above code?
Your problem is you keep overriding $default_tags variable over and over again.
At the end of your while loop, all you have is your last row with a comma at the end.
Basically you’re not storing anything but the last row in that variable.
If you do the following you would have something similar what you’re trying to do: