Schlo_50 Posted April 28, 2008 Share Posted April 28, 2008 Hi there, Justa quick one, I have hundreds of rows of data which I am displaying on a page. I wanted to print the rows out in a single table using a loop to generate and populate the <td></td>'s. I have kind of done this but for some reason my table is stretching across my page and not sticking to it's 100% width property. I think this is because of my php, not xhtml. Could someone have a quick look please? <table width="100%" border="1" cellpadding="5" class="input" cellspacing="0" bordercolor="#000000"> <tr> <td>No</td> <td>Customer</td> <td>Name</td> <td>Phone 1</td> <td>Phone 2</td> <td>Phone MB </td> <td>Fax</td> <td>URL</td> <td>Email</td> <td>Server</td> <td>Notes</td> <td>Miles RTN</td> </tr> <?php $sql = odbc_exec($odbc, "SELECT * FROM Customers") or die (odbc_errormsg()); while($row = odbc_fetch_array($sql)) { $No = $row["No"]; $Customer = $row["Customer"]; $Name = $row["Name"]; $Phone_a = $row["Phone No"]; $Phone_b = $row["Phone no2"]; $Phone_c = $row["Phone MB"]; $Fax = $row["Fax"]; $URL = $row["WebSiteUrl"]; $Email = $row["Email"]; $Server = $row["ServerFolder"]; $Notes = $row["Notes"]; $Miles = $row["Miles rtn"]; $find = '/#/i'; $replace = ''; $Server_b = preg_replace($find, $replace, $Server); $Email_b = preg_replace($find, $replace, $Email); print " <tr> <td>".$No."</td> <td>".$Customer."</td> <td>".$Name."</td> <td>".$Phone_a."</td> <td>".$Phone_b."</td> <td>".$Phone_c."</td> <td>".$Fax."</td> <td>".$URL."</td> <td>".$Email_b."</td> <td><a href=".$Server_b.">".$Server_b."</a></td> <td>".$Notes."</td> <td>".$Miles."</td> "; } print "</tr>"; print "</table>"; ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/ Share on other sites More sharing options...
soycharliente Posted April 28, 2008 Share Posted April 28, 2008 You need to close the table row inside the while loop. Also, you're forgetting quotes around your href attribute. Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/#findComment-528926 Share on other sites More sharing options...
Schlo_50 Posted April 28, 2008 Author Share Posted April 28, 2008 I reviesed the code and I still have the same problem. Any other suggestions ??? <table width="100%" border="1" cellpadding="5" class="input" cellspacing="0" bordercolor="#000000"> <tr> <td>No</td> <td>Customer</td> <td>Name</td> <td>Phone 1</td> <td>Phone 2</td> <td>Phone MB </td> <td>Fax</td> <td>URL</td> <td>Email</td> <td>Server</td> <td>Notes</td> <td>Miles RTN</td> </tr> <?php $sql = odbc_exec($odbc, "SELECT * FROM Customers") or die (odbc_errormsg()); while($row = odbc_fetch_array($sql)) { $No = $row["No"]; $Customer = $row["Customer"]; $Name = $row["Name"]; $Phone_a = $row["Phone No"]; $Phone_b = $row["Phone no2"]; $Phone_c = $row["Phone MB"]; $Fax = $row["Fax"]; $URL = $row["WebSiteUrl"]; $Email = $row["Email"]; $Server = $row["ServerFolder"]; $Notes = $row["Notes"]; $Miles = $row["Miles rtn"]; $find = '/#/i'; $replace = ''; $Server_b = preg_replace($find, $replace, $Server); $Email_b = preg_replace($find, $replace, $Email); print " <tr> <td>".$No."</td> <td>".$Customer."</td> <td>".$Name."</td> <td>".$Phone_a."</td> <td>".$Phone_b."</td> <td>".$Phone_c."</td> <td>".$Fax."</td> <td>".$URL."</td> <td>".$Email_b."</td> <td>".$Server_b."</td> <td>".$Notes."</td> <td>".$Miles."</td> </tr> "; } print "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/#findComment-528934 Share on other sites More sharing options...
phorman Posted April 28, 2008 Share Posted April 28, 2008 is this table in a containing div or other table? If not, it is expanding to 100% of the screen as you asked. Also check to make sure you do not have a css definition on TABLE that may be overwriting your 100% width designation. Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/#findComment-528938 Share on other sites More sharing options...
Schlo_50 Posted April 28, 2008 Author Share Posted April 28, 2008 No, it's not in a container. I thought setting the table width at 100% would make the table the width of the screen without scrolling? At the moment I have to scroll a long way accross the page. Even if I set the table with to 100px or 50% nothing happens to the layout of the table. Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/#findComment-528939 Share on other sites More sharing options...
soycharliente Posted April 28, 2008 Share Posted April 28, 2008 Can we see a screen shot? Honestly this doesn't sound like a PHP problem. Your data is getting accessed and written fine. You're just having trouble with the layout of the HTML. Link to comment https://forums.phpfreaks.com/topic/103273-printing-table-data/#findComment-529015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.