stualk Posted September 12, 2007 Author Share Posted September 12, 2007 It's a select from statement which selects 6 rows from a table. There will only ever be six rows in the table but each row has a field called 'supplier_name' and then a series of figures to go with that field, which we then use to formulate the totals, and eeventually we need to display the totals for each supplier name in numerical order, preferably in a row that looks like this: $supplier_name $TOTAL_REDUCED $date etc Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346934 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 are those in a mysql? Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346942 Share on other sites More sharing options...
stualk Posted September 12, 2007 Author Share Posted September 12, 2007 Yes it's a select from statement like this: $NumRows=mysql_query("select * from table"); $NumRows=mysql_num_rows($NumRows); $Result = mysql_query("select * from table") or die("No connection"); for ($i=1; $i<=$NumRows; $i++) { if ($row = mysql_fetch_array($Result)) { $id = $row["id"]; $supplier_name = $row["supplier_name"]; $logo = $row["logo"]; Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346943 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 would it not be easier to select 6 random items? then array them from the SQL; make necessary calculations then displaying it? Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346955 Share on other sites More sharing options...
stualk Posted September 12, 2007 Author Share Posted September 12, 2007 I don't know to be honest. I wouldn't know where to start because I never work with arrays, hence the reason I've laid my code out like I have. It worked fine until I started trying to display the totals in numerical order. Do you think it's best to use that method? Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346967 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 give me all your database query. i'll write some code. Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346968 Share on other sites More sharing options...
stualk Posted September 12, 2007 Author Share Posted September 12, 2007 Here's my full code for StepOne. I've commented some of it to help you understand what does what as there's an awful lot of code here! This code works perfectly for what I want it to do. There's probably a quicker way of doing it but I did it this way because I knew how to, that's all. // ========================================================================== if ($Step == "StepOne") { // ========= list of sections =============================================== require ('database.php'); // work out todays date $today = getdate(); $mon = $today['month']; $day = $today['weekday']; $dayn = $today['mday']; $year = $today['year']; if ($dayn == 1) { $dayn = "0$dayn"; } elseif ($dayn == 2) { $dayn = "0$dayn"; } elseif ($dayn == 3) { $dayn = "0$dayn"; } elseif ($dayn == 4) { $dayn = "0$dayn"; } elseif ($dayn == 5) { $dayn = "0$dayn"; } elseif ($dayn == 6) { $dayn = "0$dayn"; } elseif ($dayn == 7) { $dayn = "0$dayn"; } elseif ($dayn == { $dayn = "0$dayn"; } elseif ($dayn == 9) { $dayn = "0$dayn"; } // convert month into a code number for storage in database for sorting purposes switch ($mon) { case "January": $monthcode = '01'; break; case "February": $monthcode = '02'; break; case "March": $monthcode = '03'; break; case "April": $monthcode = '04'; break; case "May": $monthcode = '05'; break; case "June": $monthcode = '06'; break; case "July": $monthcode = '07'; break; case "August": $monthcode = '08'; break; case "September": $monthcode = '09'; break; case "October": $monthcode = '10'; break; case "November": $monthcode = '11'; break; default: $monthcode = '12'; break; } // select details of customers existing supply $NumRows=mysql_query("SELECT * FROM customers_existing where company_name = '$company_name'"); $NumRows=mysql_num_rows($NumRows); $Result = mysql_query("SELECT * FROM customers_existing where company_name = '$company_name'"); if (!$Result) die (mysql_error()); for ($i=1; $i<=$NumRows; $i++) { if ($row = mysql_fetch_array($Result)) { $id = $row["id"]; $existing_supplier = $row["existing_supplier"]; $isdn2_line_details = $row["isdn2_line_details"]; $isdn2_unit_rate = $row["isdn2_unit_rate"]; $isdn2_current_costs = $row["isdn2_current_costs"]; $isdn30_channels_line_details = $row["isdn30_channels_line_details"]; $isdn30_channels_unit_rate = $row["isdn30_channels_unit_rate"]; $isdn30_channels_current_costs = $row["isdn30_channels_current_costs"]; $analogue_lines_line_details = $row["analogue_lines_line_details"]; $analogue_lines_unit_rate = $row["analogue_lines_unit_rate"]; $analogue_lines_current_costs = $row["analogue_lines_current_costs"]; $local_line_details = $row["local_line_details"]; $local_unit_rate = $row["local_unit_rate"]; $local_current_costs = $row["local_current_costs"]; $national_line_details = $row["national_line_details"]; $national_unit_rate = $row["national_unit_rate"]; $national_current_costs = $row["national_current_costs"]; $vodafone_line_details = $row["vodafone_line_details"]; $vodafone_unit_rate = $row["vodafone_unit_rate"]; $vodafone_current_costs = $row["vodafone_current_costs"]; $orange_line_details = $row["orange_line_details"]; $orange_unit_rate = $row["orange_unit_rate"]; $orange_current_costs = $row["orange_current_costs"]; $tmobile_line_details = $row["tmobile_line_details"]; $tmobile_unit_rate = $row["tmobile_unit_rate"]; $tmobile_current_costs = $row["tmobile_current_costs"]; $o2_line_details = $row["o2_line_details"]; $o2_unit_rate = $row["o2_unit_rate"]; $o2_current_costs = $row["o2_current_costs"]; $international_line_details = $row["international_line_details"]; $international_unit_rate = $row["international_unit_rate"]; $international_current_costs = $row["international_current_costs"]; $other_line_details = $row["other_line_details"]; $other_unit_rate = $row["other_unit_rate"]; $other_current_costs = $row["other_current_costs"]; $total_current_costs = $row["total_current_costs"]; $total_current_costs = number_format($total_current_costs, 2); // display results from the above print(" <table width='95%' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'> <tr height='25'> <td bgcolor='#FF9900' width='25%'><strong><font size='2' face='Trebuchet MS'> Telecoms Tender</font></strong></td> <td bgcolor='#FF9900' width='25%'><font size='2' face='Trebuchet MS'><b>12 month offers</b></font></td> <td colspan='2' bgcolor='#FF9900' width='50%'><font size='2' face='Trebuchet MS'><strong>Offers Values</strong></font></td> </tr> </table> <br> <table width='95%' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'> <tr height='25'> <td bgcolor='#FF9900' width='50%'><strong><font size='2' face='Trebuchet MS'> Supplier</font></strong></td> <td align='right' bgcolor='#FF9900' width='25%'><font size='2' face='Trebuchet MS'><strong>Annual Cost - Lines & Calls</strong></font></td> <td align='right' bgcolor='#FF9900' width='25%'><font size='2' face='Trebuchet MS'><strong>Offer Date</strong></font></td> </tr> <tr height='25'> <td bgcolor='#FFCC99'><font size='2' face='Trebuchet MS'>Existing Suppliers: <b>$existing_supplier</b></font></td> <td bgcolor='#FFCC99'><div align='right'><font size='2' face='Trebuchet MS'><b>£$total_current_costs</b></font></div></td> <td align='right' bgcolor='#FFCC99'><font size='2' face='Trebuchet MS'><b>$dayn $mon $year</b></font></td> </tr> </table> <br> <table width='95%' border='1' cellpadding='0' cellspacing='0' bordercolor='#FFFFFF'> "); }} require ('database.php'); // select the six suppliers details from tq db $NumRows=mysql_query("select id from telequote_new") or die("Sorry Couldn't Complete Query_1a"); $NumRows=mysql_num_rows($NumRows); if ($NumRows == "0") { echo("<br><br><br><b>Sorry, there are no details currently listed.</b>"); } else { $NumRows=mysql_query("select * from telequote_new"); $NumRows=mysql_num_rows($NumRows); $Result = mysql_query("select * from telequote_new") or die("No connection"); for ($i=1; $i<=$NumRows; $i++) { if ($row = mysql_fetch_array($Result)) { $id = $row["id"]; $supplier_name = $row["supplier_name"]; $logo = $row["logo"]; // select new offer details from customers db $NumRows2=mysql_query("select id from customers") or die("Sorry Couldn't Complete Query_1a"); $NumRows2=mysql_num_rows($NumRows2); if ($NumRows2 == "0") { echo("<br><br><br><b>Sorry, there are no details currently listed.</b>"); } else { $NumRows2=mysql_query("select * from customers where company_name = '$company_name'"); $NumRows2=mysql_num_rows($NumRows2); $Result2 = mysql_query("select * from customers where company_name = '$company_name'") or die("No connection"); for ($i=1; $i<=$NumRows2; $i++) { if ($row = mysql_fetch_array($Result2)) { $id = $row["id"]; $company_name = $row["company_name"]; $isdn2a = $row["isdn2a"]; $isdn2b = $row["isdn2b"]; $isdn2c = $row["isdn2c"]; $isdn2d = $row["isdn2d"]; $isdn2e = $row["isdn2e"]; $isdn2f = $row["isdn2f"]; $isdn30a = $row["isdn30a"]; $isdn30b = $row["isdn30b"]; $isdn30c = $row["isdn30c"]; $isdn30d = $row["isdn30d"]; $isdn30e = $row["isdn30e"]; $isdn30f = $row["isdn30f"]; $analogue_linesa = $row["analogue_linesa"]; $analogue_linesb = $row["analogue_linesb"]; $analogue_linesc = $row["analogue_linesc"]; $analogue_linesd = $row["analogue_linesd"]; $analogue_linese = $row["analogue_linese"]; $analogue_linesf = $row["analogue_linesf"]; $locala = $row["locala"]; $localb = $row["localb"]; $localc = $row["localc"]; $locald = $row["locald"]; $locale = $row["locale"]; $localf = $row["localf"]; $nationala = $row["nationala"]; $nationalb = $row["nationalb"]; $nationalc = $row["nationalc"]; $nationald = $row["nationald"]; $nationale = $row["nationale"]; $nationalf = $row["nationalf"]; $vodafonea = $row["vodafonea"]; $vodafoneb = $row["vodafoneb"]; $vodafonec = $row["vodafonec"]; $vodafoned = $row["vodafoned"]; $vodafonee = $row["vodafonee"]; $vodafonef = $row["vodafonef"]; $orangea = $row["orangea"]; $orangeb = $row["orangeb"]; $orangec = $row["orangec"]; $oranged = $row["oranged"]; $orangee = $row["orangee"]; $orangef = $row["orangef"]; $tmobilea = $row["tmobilea"]; $tmobileb = $row["tmobileb"]; $tmobilec = $row["tmobilec"]; $tmobiled = $row["tmobiled"]; $tmobilee = $row["tmobilee"]; $tmobilef = $row["tmobilef"]; $o2a = $row["o2a"]; $o2b = $row["o2b"]; $o2c = $row["o2c"]; $o2d = $row["o2d"]; $o2e = $row["o2e"]; $o2f = $row["o2f"]; $other_mobilea = $row["other_mobilea"]; $other_mobileb = $row["other_mobileb"]; $other_mobilec = $row["other_mobilec"]; $other_mobiled = $row["other_mobiled"]; $other_mobilee = $row["other_mobilee"]; $other_mobilef = $row["other_mobilef"]; $internationala = $row["internationala"]; $internationalb = $row["internationalb"]; $internationalc = $row["internationalc"]; $internationald = $row["internationald"]; $internationale = $row["internationale"]; $internationalf = $row["internationalf"]; $offer_number = $row["offer_number"]; $offer_month = $row["offer_month"]; $offer_year = $row["offer_year"]; // convert offer_month code into month text switch ($offer_month) { case "01": $monthtext = 'January'; break; case "02": $monthtext = 'February'; break; case "03": $monthtext = 'March'; break; case "04": $monthtext = 'April'; break; case "05": $monthtext = 'May'; break; case "06": $monthtext = 'June'; break; case "07": $monthtext = 'July'; break; case "08": $monthtext = 'August'; break; case "09": $monthtext = 'September'; break; case "10": $monthtext = 'October'; break; case "11": $monthtext = 'November'; break; default: $monthtext = 'December'; break; } // work out total of Gamma's offer if ($supplier_name == "Gamma Telcom") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2a * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30a * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linesa * 12; $LOCAL_REDUCED = $local_line_details * $locala / 100; $NATIONAL_REDUCED = $national_line_details * $nationala / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafonea / 100; $ORANGE_REDUCED = $orange_line_details * $orangea / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobilea / 100; $O2_REDUCED = $o2_line_details * $o2a / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationala / 100; $OTHER_REDUCED = $other_line_details * $other_mobilea / 100; $TOTAL_REDUCED_1 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_1 = number_format($TOTAL_REDUCED_1); } // work out total of Thus's offer if ($supplier_name == "Thus") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2b * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30b * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linesb * 12; $LOCAL_REDUCED = $local_line_details * $localb / 100; $NATIONAL_REDUCED = $national_line_details * $nationalb / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafoneb / 100; $ORANGE_REDUCED = $orange_line_details * $orangeb / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobileb / 100; $O2_REDUCED = $o2_line_details * $o2b / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationalb / 100; $OTHER_REDUCED = $other_line_details * $other_mobileb / 100; $TOTAL_REDUCED_2 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_2 = number_format($TOTAL_REDUCED_2); } // work out total of Kingston's offer if ($supplier_name == "Kingston") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2c * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30c * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linesc * 12; $LOCAL_REDUCED = $local_line_details * $localc / 100; $NATIONAL_REDUCED = $national_line_details * $nationalc / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafonec / 100; $ORANGE_REDUCED = $orange_line_details * $orangec / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobilec / 100; $O2_REDUCED = $o2_line_details * $o2c / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationalc / 100; $OTHER_REDUCED = $other_line_details * $other_mobilec / 100; $TOTAL_REDUCED_3 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_3 = number_format($TOTAL_REDUCED_3); } // work out total of C&W's offer if ($supplier_name == "Cable and Wireless") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2d * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30d * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linesd * 12; $LOCAL_REDUCED = $local_line_details * $locald / 100; $NATIONAL_REDUCED = $national_line_details * $nationald / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafoned / 100; $ORANGE_REDUCED = $orange_line_details * $oranged / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobiled / 100; $O2_REDUCED = $o2_line_details * $o2d / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationald / 100; $OTHER_REDUCED = $other_line_details * $other_mobiled / 100; $TOTAL_REDUCED_4 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_4 = number_format($TOTAL_REDUCED_4); } // work out total of BT's offer if ($supplier_name == "British Telecom") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2e * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30e * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linese * 12; $LOCAL_REDUCED = $local_line_details * $locale / 100; $NATIONAL_REDUCED = $national_line_details * $nationale / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafonee / 100; $ORANGE_REDUCED = $orange_line_details * $orangee / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobilee / 100; $O2_REDUCED = $o2_line_details * $o2e / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationale / 100; $OTHER_REDUCED = $other_line_details * $other_mobilee / 100; $TOTAL_REDUCED_5 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_5 = number_format($TOTAL_REDUCED_5); } // work out total of Opal's offer if ($supplier_name == "Opal") { $ISDN2_REDUCED = $isdn2_line_details * $isdn2f * 12; $ISDN_THIRTY_REDUCED = $isdn30_channels_line_details * $isdn30f * 12; $ANALOGUE_LINES_REDUCED = $analogue_lines_line_details * $analogue_linesf * 12; $LOCAL_REDUCED = $local_line_details * $localf / 100; $NATIONAL_REDUCED = $national_line_details * $nationalf / 100; $VODAFONE_REDUCED = $vodafone_line_details * $vodafonef / 100; $ORANGE_REDUCED = $orange_line_details * $orangef / 100; $TMOBILE_REDUCED = $tmobile_line_details * $tmobilef / 100; $O2_REDUCED = $o2_line_details * $o2f / 100; $INTERNATIONAL_REDUCED = $international_line_details * $internationalf / 100; $OTHER_REDUCED = $other_line_details * $other_mobilef / 100; $TOTAL_REDUCED_6 = $OTHER_REDUCED + $INTERNATIONAL_REDUCED + $VODAFONE_REDUCED + $ORANGE_REDUCED + $TMOBILE_REDUCED + $O2_REDUCED + $NATIONAL_REDUCED + $LOCAL_REDUCED + $ANALOGUE_LINES_REDUCED + $ISDN_THIRTY_REDUCED + $ISDN2_REDUCED; $TOTAL_REDUCED_6 = number_format($TOTAL_REDUCED_6); } // puts the six above into an array $TOTALS = array($TOTAL_REDUCED_1, $TOTAL_REDUCED_2, $TOTAL_REDUCED_3, $TOTAL_REDUCED_4, $TOTAL_REDUCED_5, $TOTAL_REDUCED_6); print_r($TOTALS[0][0]); print_r($TOTALS[0][1]); print_r($TOTALS[0][2]); print_r($TOTALS[0][3]); print_r($TOTALS[0][4]); print_r($TOTALS[0][5]); // this commented out code is how I want to display the data in rows in numerical order when the system works as it should //echo(" // <tr height='50'> // <td bgcolor='#FFCC66' width='25%'><strong><font size='2' face='Trebuchet MS'><a href='telequote.php?Step=StepTwo&&company_name=$company_name&&supplier_name=$supplier_name&&customer_id=$customer_id'>$supplier_name</a></font></strong></td> // <td align='center' bgcolor='#FFCC66' width='25%'><a href='telequote.php?Step=StepTwo&&company_name=$company_name&&supplier_name=$supplier_name&&customer_id=$customer_id'><img border='1' src='images/logos/$logo'></a></td> // <td align='right' bgcolor='#FFCC99' width='25%'><font size='2' face='Trebuchet MS'><strong>£$TOTALS</strong></font></td> // <td align='right' bgcolor='#FFCC99' width='25%'><font size='2' face='Trebuchet MS'><strong>$offer_number $monthtext $offer_year</strong></font></td> // </tr> //"); }}} }}} print(" </table> "); print(" <br><font size='2' face='Trebuchet MS'>Click the supplier name or logo to view the offer breakdown<br>Costs exclude VAT</font> "); } Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346987 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 thats quite alot to re-create... I think that this should work... for($i=0 $i<count($TOTAL[0]); $i++) { echo($TOTAL[0][$i]); } Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-346991 Share on other sites More sharing options...
stualk Posted September 12, 2007 Author Share Posted September 12, 2007 Ok, using the following code returns nothing: $TOTALS = array($TOTAL_REDUCED_1, $TOTAL_REDUCED_2, $TOTAL_REDUCED_3, $TOTAL_REDUCED_4, $TOTAL_REDUCED_5, $TOTAL_REDUCED_6); for($i=0; $i<count($TOTALS[0]); $i++) { echo($TOTALS[0][$i]); } What effect would the positioning of these } have on it? I can only think that i've got them in the wrong place as it's not actually displaying anything. What do you think? Quote Link to comment https://forums.phpfreaks.com/topic/68998-arrays-grrrr/page/2/#findComment-347000 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.