Delete one section of information from a field full of info
Posted: Sun Jul 15, 2007 10:49 pm
Ok, hopefully I can explain this clearly enough.
I have several tables setup in my database. One is called image. image has id, url, and a bunch of other fields which stores image submission details when someone submits an image to the server. id is primary and auto increment.
Another table, userdata stores all of the registered person`s information, suchs as username, email address, favourites, etc. The field imageFavs is the field where if someone were to click on the "Add to favourites" link, id from image gets stored into imageFavs in userdata. Code shown:
Now, suppose someone has their imageFavs field loaded with a bunch of these images. What if they decide "Hey, I want to remove this one image from my favourites list."
The original guy who did the original coding for my site had a favouritedelete code but it was...crappy. It removed the , from the field but the id numbers were still left and were molded together into one large number and that messed up the entire favourites display.
How do I make the code remove just the number?
(Just so everyone knows, I`ve learned a lot about php since the guy did the codes, I lost contact with him years ago which got me started in learning php myself. So I have basic understanding of php but am still quite new to it all.)
Like if the imageFavs entry was:
,34,637,364,24,274,11
And the person wants to remove image #24
,24 would need to be removed from the list while the rest remains intact.
How is this accomplished?
I have several tables setup in my database. One is called image. image has id, url, and a bunch of other fields which stores image submission details when someone submits an image to the server. id is primary and auto increment.
Another table, userdata stores all of the registered person`s information, suchs as username, email address, favourites, etc. The field imageFavs is the field where if someone were to click on the "Add to favourites" link, id from image gets stored into imageFavs in userdata. Code shown:
Code: Select all
session_start();
include("dbcon.php");
include("auth.php");
//Date: February 25 2007
//For: secrettrance.net
//Description: Favorites the trance
$log = $_SESSION['sess_name'];
//add favorite
mysql_query("UPDATE userdata SET imageFavs=CONCAT(imageFavs,\",$id\") WHERE login='$log'");
mysql_query("INSERT INTO messagedata (recBoxID, sendBoxID, content, subject, isNew, date) VALUES ($g, '1', 'Your trance was added to $log `s favourites.<br><a href=trances.php?id=$id>Please click here to go to the trance</a>.<br>This is an automated message please do not reply.', 'New favourite added!', 1, NOW() )");
//Now let's add one to the favorite counter for the trance.
mysql_query('UPDATE `secrett1_artgallery`.`image` SET `favnum` = favnum +1 WHERE `image`.`id` =' . $id . ' LIMIT 1');
//This increments the field favnum under the row of the specified ID.
mysql_close($con);
//redirect
header("Location: trances.php?id=$id");The original guy who did the original coding for my site had a favouritedelete code but it was...crappy. It removed the , from the field but the id numbers were still left and were molded together into one large number and that messed up the entire favourites display.
How do I make the code remove just the number?
(Just so everyone knows, I`ve learned a lot about php since the guy did the codes, I lost contact with him years ago which got me started in learning php myself. So I have basic understanding of php but am still quite new to it all.)
Like if the imageFavs entry was:
,34,637,364,24,274,11
And the person wants to remove image #24
,24 would need to be removed from the list while the rest remains intact.
How is this accomplished?