Jump to content

Populating table rows with data


Texan78
Go to solution Solved by 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

Edited by Texan78
Link to comment
Share on other sites

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.