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