MySQL and PHP Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
illuminationed
Forum Newbie
Posts: 8
Joined: Fri Nov 18, 2005 10:13 am

MySQL and PHP Variables

Post by illuminationed »

Hi!i!i!i!i!i!i!i

I am having difficultly with code i am *trying* to make but need help with this feature:

I want to have 10 variables, store them in a mysql database (in the same column), extract the data and create 10 new variables

This is for a top 10 favourite links (different for each user). I have user data already stored in a table, i could add 10 more columns to the database but i know it is possible to store the data in one column!!

Help?? :?
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

you need to use arrays and serialize()

Code: Select all

$foo=serialize($array); 

$query=INSERT INTO sql_table VALUES('$foo');


you can then use unserialize() to convert the data from the table back into an array.
illuminationed
Forum Newbie
Posts: 8
Joined: Fri Nov 18, 2005 10:13 am

Post by illuminationed »

Thanks I will try it out now!!

Thanks
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

A correction to php3cho's reply:

Code: Select all

<?php

$foo=serialize($array);

$query="INSERT INTO sql_table VALUES('$foo')";

?>
illuminationed
Forum Newbie
Posts: 8
Joined: Fri Nov 18, 2005 10:13 am

Post by illuminationed »

Thanks For Your Help!!
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

sorry.
Post Reply