Creating new table rows with data using php -
i have table populated php via text file. know how create new table each new data entry trying create new row instead of whole new table. how can create new row data instead of entire table?
this have , want create new row variables in it. how can achive without creating whole new table each time. have tried couple of things no success.
$tracreport = $tracreport . "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#fff;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00ff00;'> tracking " . $tnumber[1] . " active storm cell</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table id='tracreport' width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>cell id</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>tracking since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>last strike</td </tr> <tr> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td> </tr> </table> </table> </td> </tr> </table> </td> </tr> </table>";
you try splitting table, , add loop in middle
// begin table $tracreport = $tracreport . "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#fff;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00ff00;'> tracking " . $tnumber[1] . " active storm cell</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table id='tracreport' width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>cell id</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>tracking since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>last strike</td </tr>"; // break top part of table // create loop for($k=0;$k<your max rows;$k++){ $tracreport .="<tr> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='background-color: black; color: #fff; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td> </tr>"; } // close loop // finish table $tracreport .= "</table> </table> </td> </tr> </table> </td> </tr> </table>";
edit
instead of for($k=0;$k<your max rows;$k++){...}
, if don't know total max, use foreach loop
foreach($tid $k => $v){ ... }
this loop through each of values without needing know max count
Comments
Post a Comment