Jump to content

Recommended Posts

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.

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.

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'

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  :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.