Jump to content

[SOLVED] Array display everything


timmah1

Recommended Posts

I have a variable page that ques the database, and puts everything into arrays


$sql = "SELECT * FROM preferences";
$q = mysql_query($sql);			
$a = mysql_fetch_assoc($q);

$itemCodes;
//MLB
	$itemCodes["upick_sngl"] = "$a[upick_sngl]";
	$itemCodes["upick_lck"] =  "$a[upick_lck]";
	$itemCodes["upick_mnth"] = "$a[upick_mnth]";
	$itemCodes["upick_ssn"] = "$a[upick_ssn]";
	$itemCodes["upick_po"] = "$a[upick_po]";
	$itemCodes["upick_spl"] = "$a[upick_spl]";

//NFL
	$itemCodes["fball_sngl"] = "$a[fball_sngl]";
	$itemCodes["fball_lck"] =  "$a[fball_lck]";
	$itemCodes["fball_mnth"] = "$a[fball_mnth]";
	$itemCodes["fball_ssn"] = "$a[fball_ssn]";
	$itemCodes["fball_po"] = "$a[fball_po]";
	$itemCodes["fball_spl"] = "$a[fball_spl]";

//NCAA Football
	$itemCodes["fball_ncaa_sngl"] = "$a[fball_ncaa_sngl]";
	$itemCodes["fball_ncaa_lck"] =  "$a[fball_ncaa_lck]";
	$itemCodes["fball_ncaa_mnth"] = "$a[fball_ncaa_mnth]";
	$itemCodes["fball_ncaa_ssn"] = "$a[fball_ncaa_ssn]";
	$itemCodes["fball_ncaa_po"] = "$a[fball_ncaa_po]";
	$itemCodes["fball_ncaa_spl"] = "$a[fball_ncaa_spl]";

//NCAA Basketball
	$itemCodes["bball_ncaa_sngl"] = "$a[bball_ncaa_sngl]";
	$itemCodes["bball_ncaa_lck"] =  "$a[bball_ncaa_lck]";
	$itemCodes["bball_ncaa_mnth"] = "$a[bball_ncaa_mnth]";
	$itemCodes["bball_ncaa_ssn"] = "$a[bball_ncaa_ssn]";
	$itemCodes["bball_ncaa_po"] = "$a[bball_ncaa_po]";
	$itemCodes["bball_ncaa_spl"] = "$a[bball_ncaa_spl]";

//NBA
	$itemCodes["bball_sngl"] = "$a[bball_sngl]";
	$itemCodes["bball_lck"] =  "$a[bball_lck]";
	$itemCodes["bball_mnth"] = "$a[bball_mnth]";
	$itemCodes["bball_ssn"] = "$a[bball_ssn]";
	$itemCodes["bball_po"] = "$a[bball_po]";
	$itemCodes["bball_spl"] = "$a[bball_spl]";

//Site Variables
....

 

Now, on my index page, I'm calling these variables into their appropriate sections.

This is for NCAA Basketball


foreach ($itemCodes as $fieldName => $val){
   if (strpos($fieldName, "ncaab") == 0){
     list($descr, $price) = explode("|", $val);
     $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price);
     $buffer .= "<input type=radio name=ncaab value=$fieldName> $descr: $price<br>\n";
   }
}
echo $buffer;
unset ($buffer);
reset($itemCodes);

 

This is for NFL

foreach ($itemCodes as $fieldName => $val){
   if (strpos($fieldName, "nfl") == 0){
     list($descr, $price) = explode("|", $val);
     $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price);
     $buffer .= "<input type=radio name=nfl value=$fieldName> $descr: $price<br>\n";
   }
}
echo $buffer;

and so forth..

 

But, each section is putting every variable in there, and it's suppose to be separated by sport.

Each section only has 6 different items, but it's showing all sports in each section

 

What am I doing wrong?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/134568-solved-array-display-everything/
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.