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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.