Reply to Re: an array to a database, am having hard time , help!!

Your name:

Reply:


Posted by David Haynes on 02/05/06 17:12

Jim S. wrote:
> well i got lastly, a variable that is like: $mystuff and has 1,4,3,6,7,8
>
> but i am not able to put $mystuff in the table no matter what i do.
> my table field is of a type Varchar(255) .
>
> now let us assume that i succeed (am being Very optimistic, emphasic on
> VERY)
> i know i can use explode, but i want to change the 1,4,3,6,7,8 to the
> option that i started with. so how can i do that?
> so i can have instead of numbers, basically, to have option1, option4,
> option3, ... and so on.
>
> helllllllllllllp :D

Jim,
I really wonder why you are going to all this trouble to code stuff that
is so easily modeled in the database. Is there some really compelling
reason not to use the power of the database to do your work for you?

Consider the following:
1. a table that contains a code number and a text field (lets call it codes)
2. a table that holds the non-dynamic stuff around your array. At a
minimum it has a unique id column and a description column. (lets call
it main)
3. a table that contains the unique id from the main table and a code
number from the codes table for each option in the array (lets call it
options)

Now, you can do things like:
select codes.description
from codes, options, main
where codes.code_number = options.code_number
and options.unique_id = main.unique_id
and main.unique_id = $unique_id;

to get all the selection options (as text) for an entry in your main table.

If you just wanted the code numbers, you could use:
select options.code_number
from options, main
where options.unique_id = main.unique_id
and main.unique_id = $unique_id
order by options.code_number;

for a sorted list.

-david-

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация