Replacing in MySQL?
Moderator: General Moderators
Replacing in MySQL?
Hi guys!
I've got this links directory script which allows users to have as many sub categories as they want.
Now in the MySQL database I have a field called path. Here are some examples:
Home
Home:Marketing
Home:Marketing:Subcat
Home:Marketing:Subcat:Subcat2
So what that is showing is the categories. Does that make sense? Now if I wanted to change the word Marketing to Marketing Stuff, on every other row that says Marketing would change to Marketing Stuff. Now it would look like this:
Home
Home:Marketing Stuff
Home:Marketing Stuff:Subcat
Home:Marketing Stuff:Subcat:Subcat2
Make sense? How would I do that?
THANKS!!!!
Tech
I've got this links directory script which allows users to have as many sub categories as they want.
Now in the MySQL database I have a field called path. Here are some examples:
Home
Home:Marketing
Home:Marketing:Subcat
Home:Marketing:Subcat:Subcat2
So what that is showing is the categories. Does that make sense? Now if I wanted to change the word Marketing to Marketing Stuff, on every other row that says Marketing would change to Marketing Stuff. Now it would look like this:
Home
Home:Marketing Stuff
Home:Marketing Stuff:Subcat
Home:Marketing Stuff:Subcat:Subcat2
Make sense? How would I do that?
THANKS!!!!
Tech
i think youve got your database setup wrong.
for trees like that its much easier with a table set up like this :
id int primary key auto_increment,
categoryName char(100),
parentId int
so you would then have data like this:
0 Home 0
1 Marketting 0
2 Subcat 1
3 Subcat2 2
now when you change the name of a node the children only rely on the id so large text replaces are not needed.
for trees like that its much easier with a table set up like this :
id int primary key auto_increment,
categoryName char(100),
parentId int
so you would then have data like this:
0 Home 0
1 Marketting 0
2 Subcat 1
3 Subcat2 2
now when you change the name of a node the children only rely on the id so large text replaces are not needed.
It's easy done.
I didn't test it. But i think it will work.
Love this way of programming, i forgot the english word for it.
Code: Select all
function show_group($group_id){
$query = "SELECT parrent_id,name from groups where id='".$group_id."';
if(!$result = mysql_query($query)){
echo mysql_error();
echo $query;
}
if($row = mysql_fetch_array($result)){
return show_group($rowї"parrent_id"])." <A HREF="?groep=".$group_id."">".$rowї"name"]."</A>";
}
return;
}Love this way of programming, i forgot the english word for it.
- Sevengraff
- Forum Contributor
- Posts: 232
- Joined: Thu Apr 25, 2002 9:34 pm
- Location: California USA
- Contact:
- Sevengraff
- Forum Contributor
- Posts: 232
- Joined: Thu Apr 25, 2002 9:34 pm
- Location: California USA
- Contact:
i think you mean update.
Code: Select all
UPDATE table SET name = jim WHERE name = fred