timmah1 Posted November 29, 2008 Share Posted November 29, 2008 I have a preference page that pulls info from the database $itemCodes; //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]"; $NCAABactive["bball_ncaa_active"] = "$a[bball_ncaa_active]"; $itemCodes; //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]"; $NBAactive["bball_active"] = "$a[bball_active]"; I have a page that refers to the preference page to show the variables if($NBAactive['bball_active'] == "1") { ?> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <!--start NBA table--> <td class="orderHeader" align="center">NBA Basketball</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "nba") == 0){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='nba' value='$fieldName'> $descr: $price<br>\n"; } } echo $buffer; unset ($buffer); reset($itemCodes); ?> </td> </tr> </table> <!--end NBA table--> <?php } ?> </td> <td width="0"> </td> <td width="0"></td> <td width="0"> </td> <td width="400"> <?php if($NCAABactive['bball_ncaa_active'] == "1") { ?> <!--start NCAA Basketball table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Basketball Specials</td> </tr> <tr> <td> <? 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); ?></td> </tr> </table> It pulls everything out correctly, but it's not formatting the information correctly. I have once box for NBA, one for NCAA Basketball, and the array's should go where the code is accordingly. The problem is, every variable is showing up in both boxes. For example, under the NBA box, it shows the NBA and the NCAAB, and the same thing for the NCAA Basketball box. How do I get it so that the correct items are in the correct boxes? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/ Share on other sites More sharing options...
flyhoney Posted November 29, 2008 Share Posted November 29, 2008 <?php if($NBAactive['bball_active'] == "1") { ?> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <!--start NBA table--> <td class="orderHeader" align="center">NBA Basketball</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "ncaa") === false){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='nba' value='$fieldName'> $descr: $price<br>\n"; } } echo $buffer; unset ($buffer); reset($itemCodes); ?> </td> </tr> </table> <!--end NBA table--> <?php } ?> </td> <td width="0"> </td> <td width="0"></td> <td width="0"> </td> <td width="400"> <?php if($NCAABactive['bball_ncaa_active'] == "1") { ?> <!--start NCAA Basketball table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Basketball Specials</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "ncaa") !== false){ 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-701808 Share on other sites More sharing options...
timmah1 Posted November 29, 2008 Author Share Posted November 29, 2008 This produces the exact same thing that I was getting. Here is the entire code <?php if($NBAactive['bball_active'] == "1") { ?> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <!--start NBA table--> <td class="orderHeader" align="center">NBA Basketball</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "nba") === false){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='nba' value='$fieldName'> $descr: $price<br>\n"; } } echo $buffer; unset ($buffer); reset($itemCodes); ?> </td> </tr> </table> <!--end NBA table--> <?php } ?> </td> <td width="0"> </td> <td width="0"></td> <td width="0"> </td> <td width="400"> <?php if($NCAABactive['bball_ncaa_active'] == "1") { ?> <!--start NCAA Basketball table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Basketball Specials</td> </tr> <tr> <td> <? foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "ncaab") === false){ 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); ?></td> </tr> </table> <!--end NCAA Basketball table--> <?php } ?> </td> </tr> <tr valign="top"> <td width="400"> <?php if($NCAAFactive['fball_ncaa_active'] == "1") { ?> <!--start NCAA Football table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Football Specials</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "ncaaf") === false){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='ncaaf' value='$fieldName'> $descr: $price<br>\n"; } } echo $buffer; unset ($buffer); reset($itemCodes); ?></td> </tr> </table> <!--end NCAA Football table--> <?php } ?> </td> <td width="0"> </td> <td width="0"> <!--start Blank table--> <table width="0%" cellpadding="0" border="0" cellspacing="0"> <tr> <td class="orderHeader" align="center"></td> </tr> <tr> <td> </td> </tr> </table> <!--end NCAA FB table--> </td> <td width="0"> </td> <td width="400"> <?php if($NFLactive['fball_active'] == "1") { ?> <!--start NFL table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">NFL Pro Football Specials</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "nfl") === false){ 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; unset ($buffer); reset($itemCodes); ?></td> </tr> </table> <!--end NFL table--> <?php } ?> </td> </tr> <tr valign="top"> <td colspan="5"> <?php if($MLBactive['upick_active'] == "1") { ?> <!--start Ultimate table--> <table width="400" border="1" align="center" cellpadding="3" cellspacing="0"> <tr> <td class="orderHeader" align="center">Ultimate Lock Pick</td> </tr> <tr> <td> <?php foreach ($itemCodes as $fieldName => $val){ if (strpos($fieldName, "ult") !== false){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='ult' value='$fieldName'> $descr: $price<br>\n"; } } ?> </td> </tr> </table> <!--End MLB table--> <?php } ?> Here is the preferences code $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]"; $MLBactive["upick_active"] = "$a[upick_active]"; //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]"; $NFLactive["fball_active"] = "$a[fball_active]"; //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]"; $NCAAFactive["fball_ncaa_active"] = "$a[fball_ncaa_active]"; //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]"; $NCAAFactive["bball_ncaa_active"] = "$a[bball_ncaa_active]"; //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]"; $MLBactive["bball_active"] = "$a[bball_active]"; Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-701834 Share on other sites More sharing options...
kenrbnsn Posted November 29, 2008 Share Posted November 29, 2008 Change you array to a 2-d array: <?php $itemCodes = array('mlb'=>array(),'nfl'=>array()); //MLB $itemCodes['mlb]["upick_sngl"] = $a['upick_sngl']; $itemCodes['mlb]["upick_lck"] = $a['upick_lck']; $itemCodes['mlb]["upick_mnth"] = $a['upick_mnth']; $itemCodes['mlb]["upick_ssn"] = $a['upick_ssn']; $itemCodes['mlb]["upick_po"] = $a['upick_po']; $itemCodes['mlb]["upick_spl"] = $a['upick_spl']; $MLBactive = $a['upick_active']; //NFL $itemCodes['nfl']["fball_sngl"] = $a['fball_sngl']; $itemCodes['nfl']["fball_lck"] = $a['fball_lck']; $itemCodes['nfl']["fball_mnth"] = $a['fball_mnth']; $itemCodes['nfl']["fball_ssn"] = $a['fball_ssn']; $itemCodes['nfl']["fball_po"] = $a['fball_po']; $itemCodes['nfl']["fball_spl"] = $a['fball_spl']; $NFLactive = $a['fball_active]"; ?> Then to display the values: <?php <?php if($NBAactive) { ?> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <!--start NBA table--> <td class="orderHeader" align="center">NBA Basketball</td> </tr> <tr> <td> <?php $buffer = ''; foreach ($itemCodes['nba'] as $fieldName => $val){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='nba' value='$fieldName'> $descr: $price<br>\n"; } echo $buffer; ?> </td> </tr> </table> <!--end NBA table--> <?php } ?> </td> <td width="0"> </td> <td width="0"></td> <td width="0"> </td> <td width="400"> <?php if($NCAABactive) { ?> <!--start NCAA Basketball table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Basketball Specials</td> </tr> <tr> <td> <? $buffer = ''; foreach ($itemCodes['ncaab'] as $fieldName => $val){ 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; ?></td> </tr> </table> <!--end NCAA Basketball table--> <?php } ?> </td> </tr> <tr valign="top"> <td width="400"> <?php if($NCAAFactive) { ?> <!--start NCAA Football table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">College Football Specials</td> </tr> <tr> <td> <?php $buffer = ''; foreach ($itemCodes['ncaaf'] as $fieldName => $val){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='ncaaf' value='$fieldName'> $descr: $price<br>\n"; } echo $buffer; ?></td> </tr> </table> <!--end NCAA Football table--> <?php } ?> </td> <td width="0"> </td> <td width="0"> <!--start Blank table--> <table width="0%" cellpadding="0" border="0" cellspacing="0"> <tr> <td class="orderHeader" align="center"></td> </tr> <tr> <td> </td> </tr> </table> <!--end NCAA FB table--> </td> <td width="0"> </td> <td width="400"> <?php if($NFLactive) { ?> <!--start NFL table--> <table width="100%" cellpadding="3" border="1" cellspacing="0"> <tr> <td class="orderHeader" align="center">NFL Pro Football Specials</td> </tr> <tr> <td> <?php $bufer = ''; foreach ($itemCodes['nfl'] as $fieldName => $val){ 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; ?></td> </tr> </table> <!--end NFL table--> <?php } ?> </td> </tr> <tr valign="top"> <td colspan="5"> <?php $buffer = ''; if($MLBactive) { ?> <!--start Ultimate table--> <table width="400" border="1" align="center" cellpadding="3" cellspacing="0"> <tr> <td class="orderHeader" align="center">Ultimate Lock Pick</td> </tr> <tr> <td> <?php foreach ($itemCodes['mlb'] as $fieldName => $val){ if (strpos($fieldName, "ult") !== false){ list($descr, $price) = explode("|", $val); $price = ($price == "N/A")? "N/A": sprintf("%.2f", $price); $buffer .= "<input type='radio' name='ult' value='$fieldName'> $descr: $price<br>\n"; } } ?> </td> </tr> </table> <!--End MLB table--> <?php } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-701868 Share on other sites More sharing options...
timmah1 Posted November 29, 2008 Author Share Posted November 29, 2008 Thanks Ken That works like it should. My problem now is, on the next page, I have this for the order page foreach ($_POST as $item => $itemCodesKey){ if ($item == "nba" || $item == "utl" || $item == "nfl" || $item == "ncaaf" || $item == "ncaab" ) { list($desc, $price) = explode("|", $itemCodes[$itemCodesKey]); if ($price > 0){ $hidden .= "<input type='hidden' name='$itemCodesKey' value='on'>\n"; } else { continue; } } } And then this as the review page foreach ($_POST as $item => $val){ if ($val == "on") { list($descript, $price) = explode("|", $itemCodes[$item]); $price *= $factor; $buffer .= "<td align='center'>$descript </td>"; $buffer .= "<td align='center'>'".sprintf("%.2f</td>\n", $price); $buffer .= "</tr><tr>\n"; $ttlCharge += $price; $hidden .= "<input type='hidden' name='$item' value='"; $hidden .= sprintf("%.2f' >\n", $price); } } And using the 2-d array is not showing anything that was ordered How would I change this now to reflect using a 2-d array? Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-701919 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 Does anybody have any idea on this? Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702037 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 ok, I've been banging my trying to figure out why this isn't working correctly, and I cannot figure this out. Can anybody help me out? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702260 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 I'm assumming this can't be done with the way I have it Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702464 Share on other sites More sharing options...
flyhoney Posted November 30, 2008 Share Posted November 30, 2008 I feel like maybe your are making this more complicated than it has to be. Let me see if I can cook something up, just a sec. Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702493 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 would you like to see the entire code? Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702495 Share on other sites More sharing options...
flyhoney Posted November 30, 2008 Share Posted November 30, 2008 I'm not 100% what you are trying to do here, but here is your updated code that should work with the 2d array. <?php foreach ($_POST as $item => $itemCodesKey){ if ($item == "nba" || $item == "utl" || $item == "nfl" || $item == "ncaaf" || $item == "ncaab" ) { list($desc, $price) = explode("|", $itemCodes[$item][$itemCodesKey]); if ($price > 0){ $hidden .= "<input type='hidden' name='$item' value='$itemCodesKey'>\n"; } else { continue; } } } ?> <?php foreach ($_POST as $item => $itemCodesKey){ list($descript, $price) = explode("|", $itemCodes[$item][$itemCodesKey]); $price *= $factor; $buffer .= "<td align='center'>$descript </td>"; $buffer .= "<td align='center'>'".sprintf("%.2f</td>\n", $price); $buffer .= "</tr><tr>\n"; $ttlCharge += $price; $hidden .= "<input type='hidden' name='$item' value='"; $hidden .= sprintf("%.2f' >\n", $price); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702515 Share on other sites More sharing options...
flyhoney Posted November 30, 2008 Share Posted November 30, 2008 I think you probably want to read up on PHP sessions, which would make your code a lot simpler, instead of having to carry information from page to page using hidden form fields. Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702519 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 Thank you so much. the only problem that it has now, on the bottom code, it display's the correct item and price, with lot's of other 0.00's added. You can see what it is here http://cheezyfries.net/vegasD/ and how it ends up showing the results. Don't fill anything out, it's not necessary at this point, just click continue and you'll see what I mean. Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702525 Share on other sites More sharing options...
flyhoney Posted November 30, 2008 Share Posted November 30, 2008 Yeah, looks like you need to add that check into the last bit of code: <?php <?php foreach ($_POST as $item => $itemCodesKey){ if ($item == "nba" || $item == "utl" || $item == "nfl" || $item == "ncaaf" || $item == "ncaab" ) { list($descript, $price) = explode("|", $itemCodes[$item][$itemCodesKey]); $price *= $factor; $buffer .= "<td align='center'>$descript </td>"; $buffer .= "<td align='center'>'".sprintf("%.2f</td>\n", $price); $buffer .= "</tr><tr>\n"; $ttlCharge += $price; $hidden .= "<input type='hidden' name='$item' value='"; $hidden .= sprintf("%.2f' >\n", $price); } } ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702531 Share on other sites More sharing options...
timmah1 Posted November 30, 2008 Author Share Posted November 30, 2008 Perfect! Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/134767-solved-display-arrays-properly/#findComment-702533 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.