Jump to content

Populating table rows with data


Texan78

Recommended Posts

Hello, I have a table and I want to only echo a table row when it is populated with data and not the entire table like it is now but I am having a bit of a struggle. Is it even possible to echo just a table row when there is data to be populated in it?

 

This is how it is now.

$NStracreport .= "<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 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>
		<table border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td></tr></tbody></table>";

This is what I have tried, I only want to add a new table row where the php variables are.

$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 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>"
          $tracreport .=  "<tr>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tid[$k]}</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdtime[$k]}</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdirection[$k]} °</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdistance[$k]} miles</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{strtolower($tintensity[$k])}</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{trim(strtolower($ttrend[$k]))}</td>\n";
		  $tracreport .=		"<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{trim(strtolower($tactivity[$k]))}</td>\n";
		  $tracreport .=	"</tr>\n";
						"</table>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		<table border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td></tr></tbody></table>";

-Thanks

Link to comment
Share on other sites

I got this sorted....

// begin your table
$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 thunderstorms</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 the top part of the table
// create your loop
foreach($tid as $k => $v){
         $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 your loop
   // finish your table
    $tracreport .= "</table>
                    </table>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </table>";
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.