Jump to content

Database ARRAY


JaredRitchey

Recommended Posts

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 />";
}
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/240452-database-array/
Share on other sites

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 >';
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235068
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/240452-database-array/#findComment-1235270
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.