Jump to content

tags fetching


hamza

Recommended Posts

i have tags field  in my table and tags field is optional when tags are addes

so most of the time tag field is empty with no tag.

and some time there are so many tags in a tag field of database.

 

like in my artical table i have tags field which contain

 

php, frameworks , advance php

empty field

java

jquery

 

how i can fetch all tags to show on user side and ignore empty field.

and should be unique tags in the list.

 

my fetch funtion is show as

 

/** getting all tags
     */
function get_all_tags($db)
{
	//cat array contain catagory names and id
	$tag = array();

	//getting all catagories from database.
	$result = $db->query("SELECT tags FROM `articals`", $debug = -1);

	while($row = $db->fetchNextObject($result)) {
		if ( !empty($row->tags) ) {

			 explode(',',$row->tags);
			$tag[] = $row->tags;
		}
	}
	//making unique array of
		print '<pre>';
		print_r($tag);

	$tag = array_unique($tag);



		print_r($tag);
	return $tag;
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/191195-tags-fetching/
Share on other sites

function get_all_tags($db)
{
//cat array contain catagory names and id
$tag = array();
$unique_tags = array();
//getting all catagories from database.
$result = $db->query("SELECT tags FROM `articals`", $debug = -1);
while($row = $db->fetchNextObject($result)) 
{
	if ( !empty($row->tags) ) 
	{
		$tag = explode(',',$row->tags);
		foreach($tag as $checktag)
		{
			if(!in_array($checktag,$unique_tags))
			{
				$unique_tags[] = $checktag;
			}
		}
	}
}
//making unique array of
//print '<pre>';
//print_r($tag);
//$tag = array_unique($tag);
//print_r($tag);
return $unique_tags;
}

Link to comment
https://forums.phpfreaks.com/topic/191195-tags-fetching/#findComment-1008083
Share on other sites

function get_all_tags($db)
{
//cat array contain catagory names and id
$tag = array();
$unique_tags = array();
//getting all catagories from database.
$result = $db->query("SELECT tags FROM `articals`", $debug = -1);
while($row = $db->fetchNextObject($result)) 
{
	if ( !empty($row->tags) ) 
	{
		$tag = explode(',',$row->tags);
		foreach($tag as $checktag)
		{
			if(!in_array($checktag,$unique_tags))
			{
				$unique_tags[] = $checktag;
			}
		}
	}
}
//making unique array of
//print '<pre>';
//print_r($tag);
//$tag = array_unique($tag);
//print_r($tag);
return $unique_tags;
}

 

any alternative way to fetch tags from database with unique list.

this code is not working.

Link to comment
https://forums.phpfreaks.com/topic/191195-tags-fetching/#findComment-1008094
Share on other sites

What is not working?

 

Are you getting errors, or just not what you expected?

 

no no now its working fine there is a syntax error there now solved

but one thing you are missing in there n that is case sensitive.

i am getting two php tags liek PHP and php.

now i think while insertion i should make it strtolower.

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/191195-tags-fetching/#findComment-1008100
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.