I am trying to create a row in the table within an array where there will be a subtle line within the person's additional loop Rows
Data:
symbol = & gt; AAA, volume = & gt; 100 symbols & gt; AAA, volume = & gt; 50 symbols & gt; AAA, volume = & gt; 20 symbol = & gt; BBB, volume = & gt; 100 symbols & gt; BBB, volume = & gt; 10
My code:
echo "& lt; Table & gt; \ n"; $ Sql = "SELECT * transaction from WHERE account_ id = '$ account_id' ORDER by symbol ASC"; $ Result = mysqli_query ($ conn, $ sql); $ Numofrows = mysqli_num_rows ($ result); {$ Row = mysqli_fetch_array ($ result) for ($ I = 0; $ i & lt; $ numofrows; $ i ++); Echo "& lt; tr & gt; \ n"; "Line" ["symbol ']." And & lt; Td> "$ Line ['quantity']." & Lt; / Td> \ N "; echo" & lt; / Tr & gt; \ N ";} echo" & lt; / Table & gt; \ N ";
I should have my output:
& lt; table & gt; & lt; tr & gt; // subtotal Line & lt; td & gt; AAA & lt; / td> gt; & lt; TD & gt; 170 & lt; / TD & gt; & lt; / tr & gt; & lt; tr & gt; & lt ; TD & gt; AAA & lt; / Td & gt; & lt; TD & gt; 100 & lt; / TD & gt; & lt; / TR & gt; & lt; tr & gt; & lt; TD & Gt; AAA & lt; / Td & gt; & lt; TD & gt; 50 & lt; / TD & gt; & lt; / tr & gt; & lt; tr & gt; & lt; td & gt; AAA & lt; TD & gt; 20 & lt; / tr & gt; & lt; tr & gt; & lt; td & gt; BBB & lt; / Td> // sub-total line & lt; td> 110 & lt; / td & gt; & lt; / GR & gt; & gt; TR & gt; & lt; TD & gt; BBB & lt; / TD & gt; & lt; TD & gt; 100 & lt; / TD & gt; & lt; / TR & gt; ; & Lt; tr & gt; & lt; td> gt; bbb & lt; / td & gt; & lt; td & gt; 10 & lt; / td & gt; & lt; / tr & gt; & lt ; / Table & gt;
here This will do the job you want. I made as much comment as possible.
& lt ;? Php $ sql = "SELECT * transaction WHOE account_ id = '$ account_id' ORDER by symbol ASC"; $ Result = mysqli_query ($ conn, $ sql); $ Numofrows = mysqli_num_rows ($ result); // temp data collection for table $ tmp = array (); // temp data collection = array for totals; // temp data collection = array for total costs; {$ Row = mysqli_fetch_array ($ result) for ($ I = 0; $ i & lt; $ numofrows; $ i ++); // store in variables $ sym = $ line ['symbol']; $ Qty = $ line ['quantity']; $ Cost = $ line ['cost'] * $ qty; / / If we do not have a symbol under temporary shop, then add it (empty! String in a temporary store under $ {[$ Tmp [$ sym]) {// symbol $ tmp [$ sym] = Add ''; // Our total for this symbol starts at 0 $ totals [$ sym] = 0; // Rottie symbol cost $ 0 for initial cost variable 0 [$ sym] = 0; } // Add this line to the bottom of the table for the $ tmp [$ sym]. = "& Lt; tr & gt; {$ sym} {$ qty} TD & gt; {$ cost} & lt; / TD & gt; & lt; / tr & gt; "; // Add the amount under the sign $ yoga [$ sym] + = $ qty; } Echo "table"; \ n "; // To set second loop output ($ $ = $ total = $ total = $ total) {// Total cost $ cost = $ cost [$ sym]; // sub-quote row resonates "& lt; tr class = 'subtotal' & gt; & lt; td & gt; {$ sym} & lt; / td & gt; & lt; td & gt; {$ total } & lt; td & gt; {$ cost} & lt; / TD & gt; & lt; / tr & gt; "; // resize individual rows $ tmp [$ sym]; } Echo "& lt; / table & gt; \ n";
Comments
Post a Comment