jasonsrath Posted June 29, 2010 Share Posted June 29, 2010 Hello, I took on a task at work and then realized there was nobody at work who is knowledgeable when it comes to PHP. I have an XML file which will be written to, and only the state will change. I tried getting the PHP to read the XML in order, and associate each table within the XML with a table in HTML. Not sure if I explained that well enough... How do I make the background in the HTML tables change in the order it was read from the XML? I have 48 tables total... This is what I have now, any ideas? I'm really interested in getting this to work, and any help would be appreciated. <data> <table> <name>01</name> <state>1</state> </table> <table> <name>02</name> <state>2</state> </table> <?php $xml = simplexml_load_file("tables.xml"); foreach($xml->table as $table){ if($table-state == 0){ ${'color'.$table} = "#0000FF"; }else if($table-state == 2){ ${'color'.$table} = "#FFFF00"; }else if($table-state == 3){ ${'color'.$table} = "#FF0000"; } } ?> <table align="left" width="500" height="182" border="1" cellspacing="5"> <tr> <TD ROWSPAN="2" WIDTH="60" BGCOLOR="black"> </TD> <td bgcolor="<?php echo $color1 ?>"> </td> <td bgcolor="<?php echo $color2 ?>"> </td> <td bgcolor="<?php echo $color3 ?>"> </td> <td bgcolor="<?php echo $color4 ?>"> </td> </tr> <tr> <td bgcolor="<?php echo $color5 ?>"> </td> <td bgcolor="<?php echo $color6 ?>"> </td> <td bgcolor="<?php echo $color7 ?>"> </td> <td bgcolor="<?php echo $color8 ?>"> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/206157-read-from-xml-and-apply-to-tables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.