|
Posted by Jim Michaels on 02/07/06 09:33
"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]
|