Location: PHPKode > projects > Kwalbum > kwalbum/ajax/getTags.php
<?php
/**
 * @version 2.1.1
 * @package kwalbum
 * @since 2.0 2008-08-20
 */
require_once pathinfo(__FILE__, PATHINFO_DIRNAME).'/../include/DBConnection.php';
$DB = new DBConnection();
$limit = 5;

$tags = explode(',', $DB->FilterString($P['tags']));
if (!$size = count($tags))
	exit;

$has = false;
$where = '';
$oldTags = '';
$found = false;

for($i = 0; $i < $size; $i++)
{
	$tag = trim($tags[$i]);
	if (!empty($tags[$i]))
	{
		if ($i < $size-1)
		{
			$where .= " AND Tag != '$tags[$i]'";
			$oldTags .= ($has ? ',' : null).$tag;
		}
		$has = true;
	}
}
if (!$has or !$tag)
	exit;
if ($oldTags)
	$oldTags .= ',';

echo '<ul>';

$query = 'SELECT Tag FROM '.TAG_TABLE .
	" WHERE Tag = '$tag' " .$where.
	"ORDER BY TagCount DESC " .
	"LIMIT $limit";
$result1 = $DB->Query($query);
if (0 < $result1->num_rows)
	while ($row = $result1->fetch_array())
	{
		$where .= " AND Tag != '$row[0]'";
		$found = true;
		echo "<li>$oldTags<b><big><big>$row[0]</big></big></b></li>";
	}

$query = 'SELECT Tag FROM '.TAG_TABLE .
	" WHERE Tag LIKE '$tag%' " .$where.
	"ORDER BY TagCount DESC " .
	"LIMIT $limit";
$result1 = $DB->Query($query);
if (0 < $result1->num_rows)
	while ($row = $result1->fetch_array())
	{
		$where .= " AND Tag != '$row[0]'";
		$len = strlen($tag);
		echo "<li>$oldTags<b><big><big>".
		substr($row[0], 0, $len).'</big></big></b>'.
		substr($row[0], $len).'</li>';
	}

if (!$found)
	echo "<li>$oldTags<b><big><big>$tag</big></big></b></li>";

$limit -= $result1->num_rows;
$query = 'SELECT Tag FROM '.TAG_TABLE .
	" WHERE Tag LIKE '%$tag%' " .$where.
	"ORDER BY TagCount DESC " .
	"LIMIT $limit";
$result2 = $DB->Query($query);
if (0 < $result2->num_rows)
	while ($row = $result2->fetch_array())
	{
		$pos = stripos($row[0], $tag);
		$len = strlen($tag);
		echo "<li>$oldTags".substr($row[0], 0, $pos).'<b><big><big>'.
		substr($row[0], $pos, $len).'</big></big></b>'.
		substr($row[0], $pos+$len).'</li>';
	}
?>
</ul>
Return current item: Kwalbum