Jump to content

edit keywords of product


Recommended Posts

I have products listed in my database, I need the following to edit that information. The product information itself is fairly straight forward, but when it comes to editing the keywords (for user searches of products), I'm not sure of how to go about it.


Here's what I have right now:


$sql20="UPDATE $tbl_name product_name=$product_name, product_price=$product_price, product_category=$product_category, product_link=$product_link, product_image=$product_image, product_tag=$product_tag, product_features=$product_features, product_pros=$product_pros, product_cons=$product_cons, product_description=$product_description, product_notes=$product_notes WHERE product_id = $product_id";

$ValuePart = array();
foreach($keywords as $keyword){
$ValuePart[] = "keyword=$keyword";

if (count($ValuePart) > 0 ) {
$sql24="UPDATE $tbl_name2 SET" . implode(',',$ValuePart). "WHERE product_id=".$product_id;
mysql_query($sql24) or die(mysql_error());
header("Location: ./admincp.php?edited=yes");



Am I going in the wrong direction with the keywords update? It would seem that if I do it the way I have it right now, if I have the following:



and update it to:



That the database would end up with duplicate entries. How should i combat this? I need a way to delete rows when the update reduces the amount of keywords, add entries when the update increases the amount of keywords, and just alter the existing entries when the amount of keywords stay the same.


Link to comment
Share on other sites

You need two tables.


One for your products of course.

A second for all your keywords


In the keywords table you'd have

- an id

- the keyword name

- the product id


To find all the keywords for a specific product you will need to JOIN the keywords table to the products.

SELECT * FROM products p
JOIN keywords k ON k.product = p.id


To delete a keyword, simply search for it by name and product id

DELETE FROM keywords WHERE keyword = "someword" AND product='5'

Link to comment
Share on other sites

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.

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.