JaredRitchey Posted June 26, 2011 Share Posted June 26, 2011 I store the array in a database field but it will not return the array once called. Here is what works if I have the array set manually in the PHP File. // THIS WORKS //$cleanData=array("1","2","9","3"); // AND Apparently THIS WORKS Without Commas $cleanData=array(1,9,3,2); foreach($cleanData as $cleanExtract){ if($cleanExtract == 1){ echo "one <br />"; } elseif($cleanExtract == 2){ echo "two <br />"; } elseif($cleanExtract == 3){ echo "three <br />"; } } Brings back one three two This however Does Not Work! and I'm not sure why. // Standard DB connect stuff here, then; $result=mysql_query("SELECT * FROM extractor_settings WHERE id={$batch}"); $cleanData=array($row['cleanData']); foreach($cleanData as $cleanExtract){ if($cleanExtract == 1){ echo "one <br />"; } elseif($cleanExtract == 2){ echo "two <br />"; } elseif($cleanExtract == 3){ echo "three <br />"; } } Quote Link to comment https://forums.phpfreaks.com/topic/240452-database-array/ Share on other sites More sharing options...
Andy-H Posted June 26, 2011 Share Posted June 26, 2011 You need to have a read about database normalization. If you must do it that way. // Standard DB connect stuff here, then; $result = mysql_query("SELECT * FROM extractor_settings WHERE id={$batch}"); $cleanData = implode(',', $row['cleanData']); $convert = array(1 => 'one', 'two','three','four','five','six','seven','eight','nine'); foreach($cleanData as $data) { echo ucfirst($convert[$data]) . '<br >'; } Quote Link to comment https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235068 Share on other sites More sharing options...
AbraCadaver Posted June 26, 2011 Share Posted June 26, 2011 I have no idea what you're trying to do, but there is no $row var. Try mysql_fetch_assoc($result). Quote Link to comment https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235072 Share on other sites More sharing options...
JamesThePanda Posted June 26, 2011 Share Posted June 26, 2011 Why dont you just serialize the array It would be simplier and remember to deserial it when extracting it. Quote Link to comment https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235153 Share on other sites More sharing options...
Andy-H Posted June 27, 2011 Share Posted June 27, 2011 You need to have a read about database normalization. If you must do it that way. // Standard DB connect stuff here, then; $result = mysql_query("SELECT * FROM extractor_settings WHERE id={$batch}"); $row = mysql_fetch_assoc($result); $cleanData = explode(',', $row['cleanData']); $convert = array(1 => 'one', 'two','three','four','five','six','seven','eight','nine'); foreach($cleanData as $data) { echo ucfirst($convert[$data]) . '<br >'; } My bad :$ lol Quote Link to comment https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.