mannerheim Posted July 16, 2011 Share Posted July 16, 2011 Hello, I have the following code snippet: $query = mysql_query("SELECT societati.denumire_soc, incasari.Data_Facturii, incasari.Nr_Factura, incasari.ARTICOLNUME, incasari.Valoare_factura, incasari.suma_achitata, incasari.modalitate_plata, incasari.data_achitat FROM incasari Inner Join societati ON societati.id_vip = incasari.PartID WHERE incasari.inspectorid = $vipid ORDER BY societati.denumire_soc ASC, incasari.Data_Facturii ASC, incasari.Nr_Factura ASC ") or die (mysql_error()); //$query2 = mysql_query(""); $htmloutput = ''; $htmloutput .= '<br/> <div id="wrapper3" align="center"> <center><h2>Situatie autorizatii societati comerciale</h2></center> <table width="100%" border="0" cellspacing="0 cellpadding="5"> <tr> <td class="colhead">Nr crt</td> <td class="colhead">Denumire societate</td> <td class="colhead">Data Factura</td> <td class="colhead">Nr Factura</td> <td class="colhead">Articol</td> <td class="colhead">Valoare Factura</td> <td class="colhead">Suma Achitata</td> <td class="colhead">Modalitate Plata</td> <td class="colhead">Data Plata</td> <td class="colhead">Count</td> </tr>'; $nrfactura = NULL; $tmpCount = 0; while ($row = mysql_fetch_array($query)) { if($nrfactura == $row["Nr_Factura"]) { $facturanumar = ''; $utilizator = ''; $datafacturii = ''; }elseif($nrfactura !=$row["Nr_Factura"]) { $facturanumar = $row["Nr_Factura"]; $utilizator = $row["denumire_soc"]; $datafacturii = $row["Data_Facturii"]; $tmpCount ++; } $htmloutput .= '<tr> <td class="societati">'.$tmpCount.'</td> <td class="societati">'.$utilizator.'</td> <td class="societati">'.$datafacturii.'</td> <td class="societati">'.$facturanumar.'</td> <td class="societati">'.$row["ARTICOLNUME"].'</td> <td class="societati">'.$row["Valoare_factura"].'</td> <td class="societati">'.$row["suma_achitata"].'</td> <td class="societati">'.$row["modalitate_plata"].'</td> <td class="societati">'.$row["data_achitat"].'</td> <td class="societati">'.count($row[""]).'</td> </tr>'; $nrfactura =$row["Nr_Factura"]; } $htmloutput .='</table> Now what I want to do is to determine the number of "ARTICOLNUME" for each "Nr_Factura" to determine the value of rowspan for the rows that don't duplicate. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/242116-dynamic-td-rowspan/ Share on other sites More sharing options...
wildteen88 Posted July 16, 2011 Share Posted July 16, 2011 Not really sure what you mean but try <?php $query = mysql_query("SELECT societati.denumire_soc, incasari.Data_Facturii, incasari.Nr_Factura, incasari.ARTICOLNUME, incasari.Valoare_factura, incasari.suma_achitata, incasari.modalitate_plata, incasari.data_achitat FROM incasari Inner Join societati ON societati.id_vip = incasari.PartID WHERE incasari.inspectorid = $vipid ORDER BY societati.denumire_soc ASC, incasari.Data_Facturii ASC, incasari.Nr_Factura ASC ") or die (mysql_error()); $query_data = array(); $htmloutput = ''; while ($row = mysql_fetch_array($query)) { // group the results by tye Nr_Factura column $query_data[ $row["Nr_Factura"] ][] = $row; } $htmloutput .= '<br/> <div id="wrapper3" align="center"> <center><h2>Situatie autorizatii societati comerciale</h2></center> <table width="100%" border="1" cellspacing="0 cellpadding="5"> <tr> <td class="colhead">Nr crt</td> <td class="colhead">Denumire societate</td> <td class="colhead">Data Factura</td> <td class="colhead">Nr Factura</td> <td class="colhead">Articol</td> <td class="colhead">Valoare Factura</td> <td class="colhead">Suma Achitata</td> <td class="colhead">Modalitate Plata</td> <td class="colhead">Data Plata</td> <td class="colhead">Count</td> </tr>'; $nrfactura = NULL; $tmpCount = 0; $row_span = 0; // render the table. Applying row span to the Nr_fatcutura column foreach($query_data as $allduprows) { // calculate the how many rows need to be spanned $row_span = count($allduprows); foreach($allduprows as $row_key => $row) { if($nrfactura == $row["Nr_Factura"]) { $facturanumar = ''; $utilizator = ''; $datafacturii = ''; } elseif($nrfactura !=$row["Nr_Factura"]) { $facturanumar = $row["Nr_Factura"]; $utilizator = $row["denumire_soc"]; $datafacturii = $row["Data_Facturii"]; $tmpCount ++; } $htmloutput .= '<tr> <td class="societati">'.$tmpCount.'</td> <td class="societati">'.$utilizator.'</td> <td class="societati">'.$datafacturii.'</td>'; // apply the row span to the 'Nr Factura' column if($row_span > 1 && $row_key == 0) { $htmloutput .= ' <td class="societati" rowspan="'.$row_span.'">'.$facturanumar.'</td>'; } elseif($row_span <= 1) { $htmloutput .= ' <td class="societati">'.$facturanumar.'</td>'; } $htmloutput .= ' <td class="societati">'.$row["ARTICOLNUME"].'</td> <td class="societati">'.$row["Valoare_factura"].'</td> <td class="societati">'.$row["suma_achitata"].'</td> <td class="societati">'.$row["modalitate_plata"].'</td> <td class="societati">'.$row["data_achitat"].'</td> <td>'.$row_span.'</td> </tr>'; $nrfactura = $row["Nr_Factura"]; } } $htmloutput .= '</table>'; echo $htmloutput; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242116-dynamic-td-rowspan/#findComment-1243433 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.