Rakki Posted December 3, 2008 Share Posted December 3, 2008 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: 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 Quote Link to comment https://forums.phpfreaks.com/topic/135383-solved-formatting-php/ Share on other sites More sharing options...
rhodesa Posted December 3, 2008 Share Posted December 3, 2008 you need to move your <table> tags outside of the loop. so the order of code would be: print open table tag print header row with column titles start loop print row for each entry end loop print close table tag Quote Link to comment https://forums.phpfreaks.com/topic/135383-solved-formatting-php/#findComment-705160 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135383-solved-formatting-php/#findComment-705163 Share on other sites More sharing options...
Rakki Posted December 3, 2008 Author Share Posted December 3, 2008 Thanks, thats a great help! It looks much better! Quote Link to comment https://forums.phpfreaks.com/topic/135383-solved-formatting-php/#findComment-705182 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.