Jump to content

Recommended Posts

Hey all.

 

I'm kinda new to PHP, but really enjoying it at the moment and I've come across a bit of a hump. I'm currently doing an assignement to display XML data using PHP. I've coded everything so it all works fine, but my problems lays with how I can format it to look better - which isn't needed for the assignment, I would just like to make it look more appealing. I'm currently pulling data from three different sources, but my data is presented in 3 different sections:

 

 

tempwd9.jpg

 

The code for this section is as follows:

 

echo "<div >";

for ($c =0; $c <= 2; $c++) {

echo "<table width=700 border=1 cellpadding=3 cellspacing=1>";

echo "<tr><th><b>Location</b></th><th><b>Current Conditions</b> </th><th>Temperature</b> </th><th><b>Wind Speed</b></th><th><b>Wind Chill</b></th></tr>";

echo "<td>".data_extract($data, "location", $c)."</td>";

echo "<td>".data_extract($data, "weather", $c)."</td>";

echo "<td>".data_extract($data, "temperature_string", $c)."</td>";

echo "<td>".data_extract($data, "wind_string", $c)."</td>";

echo "<td>".data_extract($data, "windchill_string", $c)."</td>";

echo "<img src=\"".data_extract($data, "icon_url_base", $c).data_extract($data, "icon_url_name", $c)."\"></img>"."";

}

echo "</table>";

echo "</div>";

 

Can anyone shed some light on how I may tackle how to put all the data in the same table, rather than have 3. The answer seems like it would be really simple, but I've tried a lot of different ways, and just can't seem to get it.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/135383-solved-formatting-php/
Share on other sites

If the headings are the same you only need to use them once.

 

echo "<div >";
echo "<table width=700 border=1 cellpadding=3 cellspacing=1>";
echo "<tr><th><b>Location</b></th><th><b>Current Conditions</b> </th><th>Temperature</b> </th><th><b>Wind Speed</b></th><th><b>Wind Chill</b></th></tr>";
for ($c =0; $c <= 2; $c++) {
echo "<tr><td>".data_extract($data, "location", $c)."</td>";
echo "<td>".data_extract($data, "weather", $c)."</td>";
echo "<td>".data_extract($data, "temperature_string", $c)."</td>";
echo "<td>".data_extract($data, "wind_string", $c)."</td>";
echo "<td>".data_extract($data, "windchill_string", $c)."</td></tr>";
echo "<tr><td colspan=5><img src=\"".data_extract($data, "icon_url_base", $c).data_extract($data, "icon_url_name", $c)."\"></img></td></tr>"; // not sure if this is kosher or where you want it. Probably should be in a column also. modified it to be in it's own row.
}
echo "</table>";
echo "</div>";

 

That should get you the desired results.

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.