You are here: Re: an array to a database, am having hard time , help!! « PHP Programming Language « IT news, forums, messages
Re: an array to a database, am having hard time , help!!

Posted by Jim S. on 10/13/91 11:39

hey jim, thanks , i will try that, thanks a lot. and that new mysqli_prepare
is interesting, i will check it out.

i finally solved the problem in a funcky way, (using serialize though)
instead of saving the values (1, 2,3,,,...) i saved the labels ofthe menus,
basically, i had a label same as the value, and did the
serialize/unserialize

since i thought, it will be a hassle for me after saving the numerical
values to get the "labels" associated with it. (any comment on that?)
further more , i used a multi select menu, like it was suggested to me
instead the file select/menus and when echoing it i just did a
while/endwhile .

that's it folks, i really thank everyone that pitched in for the help.
thanks
Jim

"Jim Michaels" <jmichae3@nospam.yahoo.com> wrote in message
news:3eidnUtKWY1303XeRVn-uA@comcast.com...
>
> "Jim Michaels" <jmichae3@nospam.yahoo.com> wrote in message
> news:xr-dncOKpOqAoXXeRVn-oQ@comcast.com...
>> "Jim S." <jim@yeah.com> wrote in message
>> news:d3oFf.10916$rH5.4077@newsread2.news.atl.earthlink.net...
>>> 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.
>>
>
> or more specifically,
>
> have you tried putting single quotes around the data when you INSERT it?
> $q=mysql_query("INSERT INTO tablename(columnname) VALUES ('$mystuff')",
> $link);
>
>
> if you are having problems with the length of your data, change the type
> from VARCHAR to LONGTEXT.
>
> if you want a more direct method of storing arrays because you have
> strings in them or quotes, commas, or other SQL punctuation and such, then
> use serialize(), unserialize() and a TINYBLOB, BLOB(), or MEDIUMBLOB data
> type.
> with binary data types like that, if you have PHP5 and MYSQL5, try using
> the mysqli functions like mysqli_prepare(), etc. for your inserts. you'll
> get a little more speed. you also don't have to encode your binary data
> with mysql_real_escape_string().
>
>>
>>
>>> 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
>>> <xclarky@gmail.com> wrote in message
>>> news:1139144662.354557.102930@f14g2000cwb.googlegroups.com...
>>>> ENUM is basically the same as SET however it allows NULL values.
>>>> Therefore this would be a wrong data type to use considering what you
>>>> are storing. Both basically set up a list of acceptable values for the
>>>> field.
>>>>
>>>> As you are storing an array, I would advise you to convert it to a
>>>> string so you have a list of numbers, separated by a divider; as you
>>>> have done.
>>>>
>>>> You can then store that list in your field, VARCHAR or TEXT should be
>>>> appropriate depending on the length of the list.
>>>>
>>>> When retrieving the data you can use explode() or array_map() to create
>>>> an array of the numbers for whatever purpose you wish. Alternatively
>>>> you can use MySQL functions in the WHERE clause for statements if you
>>>> are looking to perform a action where a match is found for a specific
>>>> value in your list.
>>>>
>>>> Hope that helps you.
>>>>
>>>
>>>
>>
>>
>
>

 

Navigation:

[Reply to this 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

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