DB String -> Array

admin

Administrator
Staff member
After hours searching the forums I have been unable to succesfully implement any ideas I have gathers so I am pleading for help!

What I am doing is pulling 1 field from a row that contains a string of sizes.

ie. "small", "medium", "large".

My problem is that I cannot seem to turn that string into an array once I have pulled it from the database.

My goal is top populate a <select> tag with the list of sizes in the table field.


I have heard alot of talk about explode() and implode() and serialize() and unserialize() but have been unable to grasp the concept. This is the first time i have tried to access arrays from the database.

Any help on this matter would be greatly appreciated.

Here is the snipet of code I am working on.

if (!($result2 = mysql_db_query($DB,"SELECT sizes FROM apparrel_info where item_no='$item_no'")))
{
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
return 0 ;
}
echo "$size[0]";
if(mysql_num_rows($result2) == 0){// if there are no sizes then do not print select
echo " ";
} else {
echo "<select name=sizes>";
$row = mysql_fetch_array($result2);
$sizes = $row['sizes'];
explode(",",$sizes);

for ($i = 0; $i < $sizes; $i++){

echo "<option value=http://www.phpbuilder.com/board/archive/index.php/\"$sizes[$i]\">$sizes[$i]</option><br>";
}

I know this is not at all correct (since it doesnt work) so any direction would help.

Thanks,

John
 
Back
Top