Pennimus
09-24-2006, 05:17 PM
Some of you will likely remember me trying to build a page tagging system a while back (original thread here (http://www.codingforums.com/showthread.php?t=95051)) which at the time stumped me, so I gave it a rest.
I'm back on it and approaching from a slightly different angle which is basically working, but I have a few issues. I'll walk you through the whole process so you can get a better idea of the whole thing and where gremlins are creeping in to the system.
The tags for each bookmarked page (up to three) are stored in seperate columns in the database.
//Retrieve tags and combine them into a single string
$rawtags = mysql_query ("SELECT tag1, tag2, tag3 FROM bookmarks") or die(mysql_error());
while ($array = mysql_fetch_array($rawtags)) {
$taglist .= $array['tag1'].',';
$taglist .= $array['tag2'].',';
$taglist .= $array['tag3'].',';
}
This returns a long list with each tag seperated by a comma. Note the blank values in places, this is where a page has only been tagged with one or two tags, often resulting in tag3 being an empty column. This causes problems later on.
All Tags CSV:
Design,Tools,,Jobs,Search Engine Optimisation,,Shopping,Product,Health & Fitness,Tools,Design,Writing,Tools,Eye Tracking,Usability,Tools,Link Building,Website Management,Tools,Search Engine Optimisation,,Tools,Usability,Accessibility,
// Next, turn it back into an array and remove duplicates
$tags = array_unique(explode(",", $taglist));
This returns the following. It's getting there, but the blanks are now taking up their own slots in the array, and additionally because I stripped many of the values out, the array has many keys which simply don't exist anymore.
Raw Unique Tags:
Array ( [0] => Design [1] => Tools [2] => [3] => Jobs [4] => Search Engine Optimisation [6] => Shopping [7] => Product [8] => Health & Fitness [11] => Writiing [13] => Eye Tracking [14] => Usability [16] => Link Building [17] => Website Management [23] => Accessibility )
// Finally echo each tag individually (so each one can be a seperate link)
$numtags = count($tags);
for ($i=0; $i < $numtags; $i++) {
echo $tags[$i].', ';
}
Because I'm relying on the key value to go through the whole array and comparing it to the total number of unique tags I end up with an incomplete list. In this case there are 14 unique tags, but the keys go up to 23.
List Of Processed Unique Tags:
Design, Tools, , Jobs, Search Engine Optimisation, , Shopping, Product, Health & Fitness, , , Writiing, , Eye Tracking,
Also, although not a fundamental problem, the multiple blank spaces that are getting echoed out are compromising the aesthetics of the final product.
Has anyone got any suggestions on how I can solve this? Is there some way to reassign the keys of the array so that they run from 1-14? Or perhaps loop through the array without relying on counting the items?
How about stripping those irritating blank values?
Thanks for reading.
I'm back on it and approaching from a slightly different angle which is basically working, but I have a few issues. I'll walk you through the whole process so you can get a better idea of the whole thing and where gremlins are creeping in to the system.
The tags for each bookmarked page (up to three) are stored in seperate columns in the database.
//Retrieve tags and combine them into a single string
$rawtags = mysql_query ("SELECT tag1, tag2, tag3 FROM bookmarks") or die(mysql_error());
while ($array = mysql_fetch_array($rawtags)) {
$taglist .= $array['tag1'].',';
$taglist .= $array['tag2'].',';
$taglist .= $array['tag3'].',';
}
This returns a long list with each tag seperated by a comma. Note the blank values in places, this is where a page has only been tagged with one or two tags, often resulting in tag3 being an empty column. This causes problems later on.
All Tags CSV:
Design,Tools,,Jobs,Search Engine Optimisation,,Shopping,Product,Health & Fitness,Tools,Design,Writing,Tools,Eye Tracking,Usability,Tools,Link Building,Website Management,Tools,Search Engine Optimisation,,Tools,Usability,Accessibility,
// Next, turn it back into an array and remove duplicates
$tags = array_unique(explode(",", $taglist));
This returns the following. It's getting there, but the blanks are now taking up their own slots in the array, and additionally because I stripped many of the values out, the array has many keys which simply don't exist anymore.
Raw Unique Tags:
Array ( [0] => Design [1] => Tools [2] => [3] => Jobs [4] => Search Engine Optimisation [6] => Shopping [7] => Product [8] => Health & Fitness [11] => Writiing [13] => Eye Tracking [14] => Usability [16] => Link Building [17] => Website Management [23] => Accessibility )
// Finally echo each tag individually (so each one can be a seperate link)
$numtags = count($tags);
for ($i=0; $i < $numtags; $i++) {
echo $tags[$i].', ';
}
Because I'm relying on the key value to go through the whole array and comparing it to the total number of unique tags I end up with an incomplete list. In this case there are 14 unique tags, but the keys go up to 23.
List Of Processed Unique Tags:
Design, Tools, , Jobs, Search Engine Optimisation, , Shopping, Product, Health & Fitness, , , Writiing, , Eye Tracking,
Also, although not a fundamental problem, the multiple blank spaces that are getting echoed out are compromising the aesthetics of the final product.
Has anyone got any suggestions on how I can solve this? Is there some way to reassign the keys of the array so that they run from 1-14? Or perhaps loop through the array without relying on counting the items?
How about stripping those irritating blank values?
Thanks for reading.