jacko_162 Posted August 5, 2011 Share Posted August 5, 2011 I have coded a small CMS script which allows me to add products to a sort of "online" catalogue. what i want to do is allow myself and others with access to be able to edit a product and add "tags" for instance if i had a yellow product i would add the tag "yellow" then eventully i will use the built in search function to search for specific tags, and also allow users to click on tags in a sort of tag cloud to browse for anything with the same or popular tags. How would i go about this? would i store the tags in an array for each product in the products table?? for instance; TAGS: "yellow, big, bright, popular, special" if i store them in the above format, how would i randomly show a list of 10 tags from multiple products on my homepage or even better the top 10 most common tags? any help, pointers or source code to work from would be awsomly appreciated, as im still learning PHP and reading code and figuring it out is the best way im learning. Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/ Share on other sites More sharing options...
requinix Posted August 5, 2011 Share Posted August 5, 2011 Create a table with two columns: the product ID and the tag. There will be multiple rows for each product. Add a tag by adding a row, delete a tag by deleting a row, and search for a tag by searching the table and JOINing it with the product table. Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252762 Share on other sites More sharing options...
jacko_162 Posted August 5, 2011 Author Share Posted August 5, 2011 i was thinking this way, dont i need a 3rd column for id and hae it primary key? Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252796 Share on other sites More sharing options...
msaz87 Posted August 5, 2011 Share Posted August 5, 2011 i was thinking this way, dont i need a 3rd column for id and hae it primary key? You could, but you don't have to. You would just have your products table where you grab the ID, then a row for the tags. So the same product ID would show up multiple times for however many tags you had and when you went to delete a tag, it'd query by the product ID and tag = 'tag-to-delete' Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252804 Share on other sites More sharing options...
jacko_162 Posted August 5, 2011 Author Share Posted August 5, 2011 OK manually added some tags in a db table as follows: 3x colums "id" "pid" "tag" id = auto_increment and primary key, pid is equal to the product ID and tag is obviosuly the tag. i use the following query to fetch data randomly; // Query to randomly select multiple tags for this product $sqltag = mysql_query("SELECT `tag` FROM tags WHERE `pid`=47 ORDER BY RAND() LIMIT 0,8"); $rowtag = mysql_fetch_array($sqltag); how do i echo the multiple results? if i use; <? echo $rowtag['tag']; ?> i just get the 1 random result returned instead of the 8? help please Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252849 Share on other sites More sharing options...
msaz87 Posted August 5, 2011 Share Posted August 5, 2011 Instead of: $rowtag = mysql_fetch_array($sqltag); Do this: while($rowtag = mysql_fetch_array($sqltag)) { echo $rowtag['tag']."<br/>"; } Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252852 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 edit: This is happening alot, sorry about that msaz87 we posted exactly at the same time. i'll take off my example. Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252853 Share on other sites More sharing options...
jacko_162 Posted August 5, 2011 Author Share Posted August 5, 2011 Sweet thanx guys Quote Link to comment https://forums.phpfreaks.com/topic/243964-coding-the-ability-to-add-tags-to-my-products/#findComment-1252856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.