Forum Moderators: coopster

Message Too Old, No Replies

Quick Question -

1 row vs, multiple. Which would work better?

         

mcjohnson

9:51 am on Aug 22, 2007 (gmt 0)

10+ Year Member



before I get to far into this little coding effort I am working on, I thought I might want to pose this question:

I want to display a drop-down box populated with information from a table.

If I have all of the pieces of data in the MySql database in a single row separated by a comma, will I be able to get them out, explode them and then display them all?

i.e:

row 1: cincinnati, jacksonville, davenport, bryan

or would it be better to have them lined up in separate rows, i.e.

1 cincinnati
2 jacksonville
3 davenport, etc

or, would either work? I would rather do the former, but should be able to work it out either way. Which would you do if you were going to generate a dynamic dropdown?

P

Habtom

10:00 am on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mcjohnson, that is a good question.

Perhaps there is no big difference as such, but I would go with storig them in rows. If they were referenced to another field in the future or a field is to be added somewhere, comma thing won't have much flexibility. Or will it?

Habtom

d40sithui

11:26 am on Aug 22, 2007 (gmt 0)

10+ Year Member



i vote the multiple row if you want to do the dynamic dropdown. this way u can assign an id to each, and thus will be eaiser to use that id to generate your sub-dynamic drop downs(if any). plus its simpler.

datacaliber

1:39 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



Definitely go with multiple rows. Technically they could both work in the context you're talking about. But doing it in one row defeats the purpose of using a relational database.

You want to have a table for your cities and assign one a unique id. Whenever you reference that city, use that ID and not the city name. What happens if the City were to rename itself? You could potentially have to manually change a lot of data. And if the City renamed itself to one that currently exists... On the other hand, if you split the city into rows in their own table, you have to change one entry. The city name changing scenario is pretty extreme, but having a misspelling that goes unchecked or two cities with the same name is pretty common.

Really, anytime you have a comma delimited list in a row, you should have to justify it. I'm not saying it's always wrong, but it's something you should have reservations about.

But like I said, both would work.

mcjohnson

1:46 am on Aug 27, 2007 (gmt 0)

10+ Year Member



thanks all! Have a great week,