Jump to content

Printing table data


Schlo_50

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

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