Forum Moderators: coopster

Message Too Old, No Replies

variables within a mysql table?

I hope this makes since to anyone...

         

PokeTech

10:53 pm on May 11, 2008 (gmt 0)

10+ Year Member



Ok... Well what I'm trying to do is to get like several pieces of information and store them into a mysql.

So if this is my table:

CREATE TABLE `example` (
`id` int(10) unsigned NOT NULL auto_increment,
`text` text NOT NULL,
PRIMARY KEY (`id`),
);

I'm trying to get it so that if I have like several form fields and I enter text into each of the text boxs I want all that stuff to be saved in the text row. But then I want them to kind of be separated in that table cell thing so that later I can come back and extract it piece by piece.

I was looking in my mysql database for examples and this is what I found:

a:8:{i:3;i:3;i:9;i:9;i:10;i:1;i:8;i:5;i:7;i:1;i:2;i:1;i:13;i:1;i:19;i:2;}

something like that. But then some how the person who made the PHP program that put that stuff in the sql database some how made it so he/she could extract it to. Thats what I'm trying to do... How would you do something like that?

I'm hoping this makes since =/

cameraman

8:11 am on May 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like it's been serialize [us.php.net]d.

PokeTech

10:48 am on May 16, 2008 (gmt 0)

10+ Year Member



Is there a way to like display serialized stuff in like order, or pull out the information individually and then is it possible to edit them individually to?

If so is there a good tutorial somewhere someone could show me?

PHP_Chimp

12:11 pm on May 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that the information has been serialized then you can unserialize [us.php.net] it.
You can then work with it and serialize it again for storage.

PokeTech

1:46 am on May 18, 2008 (gmt 0)

10+ Year Member



Ok Well I think I've got most of it down so far except one thing which is adding a number to a certain part of the array thing.

Lets say this is my original array that I got after I unserialized it from my mysql:

$ages = array("3"=>1, "28"=>3);

I want to now how I can increase $ages[3] by 1 and then put it back in the array and update it into the sql. So when its in the mysql it should look like this:

a:2:{i:3;i:2;i:28;i:3;}

and unserialized it should look like this:

array(2){[3]=>int(2)[28]=>int(3)}

Or something like that...

Can anyone help?

PHP_Chimp

8:58 am on May 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could just keep it very simple

// get the result from the database
$ages = unserialize($result);
$ages[3] = $ages[3]+1;
$to_be_returned_to_database = serialize($ages);

Or are you trying to work within the database?

PokeTech

7:06 pm on May 25, 2008 (gmt 0)

10+ Year Member



I think that might work. I'll give it a go.