473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

I want to know how I can do this using PHP & MySQL

21
I want to add tags for a paricular image in my db table.
I want these tags to be stored in one table field.
lets say I entered the following tags for an image:

house
mountainside
lake
greenery

I want these tags to be saved in 1 field named Tags separated by a delimiter.

house:mountainside:lake:greenery

the above is wat shld be stored in my database.

can someone pls tell me how to do this?

like using somethin opposite as the explode() in php.

thanks in advance!!!
Jul 31 '08 #1
8 1324
r035198x
13,262 8TB
The opposite of explode is implode()
Jul 31 '08 #2
nse111
21
sorry guys i guess thats ike really simple. i used implode
Jul 31 '08 #3
nse111
21
thanks.....................................
Jul 31 '08 #4
r035198x
13,262 8TB
sorry guys i guess thats ike really simple. i used implode
No problem. Just remember to refuse to write any code if you don't have the manual with you.
Jul 31 '08 #5
Atli
5,058 Expert 4TB
I should mention that you really shouldn't store more than one piece of data in a single field, like you do with your tag field.
(Check out Database normalization and Table structure for details on that).

Each single piece of data should be placed in it's own field, which in your case, would require a new table to be created.

Consider this table layout. It's not perfect but it's a big improvement:
Expand|Select|Wrap|Line Numbers
  1. Image
  2. ----------
  3. ImageID Int (PK)
  4. ImageName Char(Unique)
  5. Etc...
  6. ----------
  7.  
  8. ImageTag
  9. ----------
  10. TagID Int (PK)
  11. ImageID Int (FK)(Unique)
  12. TagName Char (Unique)
  13. ----------
  14.  
In the second table the ImageID and TagName fields would share a Unique key, making it impossible to insert the same tag twice for the same image.

This may seem unnecessary extra trouble, but you should always try to normalize your database. It makes it much easier to work with, especially if it ever needs to be extended or altered.
Jul 31 '08 #6
dlite922
1,584 Expert 1GB
I should mention that you really shouldn't store more than one piece of data in a single field, like you do with your tag field.
(Check out Database normalization and Table structure for details on that).

Each single piece of data should be placed in it's own field, which in your case, would require a new table to be created.

Consider this table layout. It's not perfect but it's a big improvement:
Expand|Select|Wrap|Line Numbers
  1. Image
  2. ----------
  3. ImageID Int (PK)
  4. ImageName Char(Unique)
  5. Etc...
  6. ----------
  7.  
  8. ImageTag
  9. ----------
  10. TagID Int (PK)
  11. ImageID Int (FK)(Unique)
  12. TagName Char (Unique)
  13. ----------
  14.  
In the second table the ImageID and TagName fields would share a Unique key, making it impossible to insert the same tag twice for the same image.

This may seem unnecessary extra trouble, but you should always try to normalize your database. It makes it much easier to work with, especially if it ever needs to be extended or altered.
I could go either way, actually. If images had an average of 5 tags, your image table would be five times larger.

when searching, you could always use the "LIKE" clause to search for something like "%:mountain:%", in the tag field.

As for "searching" to eliminate duplicates. The tag field will be an array of only several fields, array searching would be fast.

Just some thoughts, It depends on the use and your particular needs,



Dan
Aug 1 '08 #7
Atli
5,058 Expert 4TB
I could go either way, actually. If images had an average of 5 tags, your image table would be five times larger.

when searching, you could always use the "LIKE" clause to search for something like "%:mountain:%", in the tag field.

As for "searching" to eliminate duplicates. The tag field will be an array of only several fields, array searching would be fast.

Just some thoughts, It depends on the use and your particular needs,



Dan
Using the LIKE clause to search through a large database will most likely take a very long time. Searching through a long string will usually take much longer than simply matching two short strings. Not to mention that searching will render indexes pretty much useless (although I'm not 100% sure on that).

But putting that aside, normalization is less about ease of use and more about maintaining data integrity, reducing the chance of data corruption and other abnormalities, making the database easy to maintain and extend. (among other things.)

Like with the field we are discussing in this thread, it would be extremely easy to corrupt the data or insert duplicates. MySQL considers it a single text field, which leaves it completely in the hands of the API to maintain. The developer of each application that is to use this data must develop their own code to maintain it, which is just silly considering you already have an open connection to a highly refined database engine that specializes in such tasks.
Aug 1 '08 #8
nse111
21
Hmmm really interesting facts guys.. thanks so much I will really consider them! thanks again
Aug 5 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: madeo | last post by:
hi, i'm looking for some script which would export address labels from a mysql db to pdf ... There's an exapmle, but i'm not able to convert it for using with mysql ... can anybody help? THX...
3
by: Eric Linders | last post by:
Hi, Pretty new to PHP/MySQL, but I have some programming experience in a past life. Hopefully you can help me out as I learn PHP/MySQL! :-) I have a MySQL database that includes customer...
1
by: Ken | last post by:
First time I have installed mysql. I have not been able to connect to the server/database with a new php installation. I have installed IIS. Do I need this for mysql? The php works fine. ...
7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
by: Eric Linders | last post by:
Hello, Our company currently processes a few hundred form submissions through our site. Up till now, the contents of the form has been sent to our customer support staff in real-time. Each...
10
by: Bob Hollness | last post by:
AAARRRGHHH!!! I fix my server, well, I rebuilt it actually. It runs Suse 9.2 and MySQL 4.0.21 When I try to do a Recordset.Update I get the following error. Error Number = -2147217871...
0
by: smileman | last post by:
Hi In 5.0 Manual, I see XA Interface( use SQL,Connector/J ). But,
2
by: necro1000 | last post by:
Hi, I am creating a website and I need some information off an online mySql database. Locally, I am using the MySql Connector provided by the mySql developers themselves. When I upload the page...
1
by: Abhay Gupta | last post by:
I want to block some websites with using database(Mysql). If i enter the name or url of the website into the database then nobody can access this website.Is it possible?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.