Page 1 of 1

Arrays in DB?????

Posted: Sun Mar 27, 2005 1:14 pm
by Perfidus
What happens if I write the following text in a database row call numbers:

"one", "two", "three", "four"

and after I try to recover it like this:

Code: Select all

$result= mysql_query("SELECT numbers FROM arrays" ,$link);
while ($row = mysql_fetch_array($result)){
$numbers=array($row['numbers']);
}
I thought I will recover an array, but it doesn't work.
Any hints?

Posted: Sun Mar 27, 2005 1:21 pm
by John Cartwright

Posted: Sun Mar 27, 2005 1:30 pm
by Perfidus
I have tried like this:

Code: Select all

$result= mysql_query("SELECT numbers FROM arrays" ,$link);
while ($row = mysql_fetch_array($result)){
$numbersbeta=unserialize($row['numbers']);
}
$numbers=array($numbersbeta);
But it was a mess too.
Is it the right way to use it?

Posted: Sun Mar 27, 2005 1:54 pm
by John Cartwright
the content you are pulling from the database has to already be serialized.


1) when adding into the db serialize the content
2) when pulling from the db unserialize the content

Posted: Sun Mar 27, 2005 3:15 pm
by Perfidus
Yeah!, That worked out for me!

New question master:

Code: Select all

array_push($cities, "$newcity");
sort($cities);
$clave = array_search('$newcity', $cities);
echo $clave."<br>";
Why this is echoing nothing?

Posted: Sun Mar 27, 2005 4:13 pm
by John Cartwright
Where is $newcity coming from?

Code: Select all

echo $newcity;
to see if its the expected value