Jump to content

[SOLVED] table is not aligned right


cluce

Recommended Posts

can someone tell me how to fix this table thats in the attachment. before I pull all my hair. 

I know I am looping the table border I just dont know how to get it to work outside the loop.

 

here is my code..

<?php
//connect to database
include'db.php';

//get all data from table
$sql = "SELECT * from products";
$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));


//if authorized, get the values
while ($info = mysqli_fetch_array($result)) {
	$ItemNo = stripslashes($info['Item_No']);
	$Man = stripslashes($info['Manufacturer']);
	$Cat = stripslashes($info['Category']);
	$Des = stripslashes($info['Description']);
	$Model = stripslashes($info['Model']);
	$Qty = stripslashes($info['Qty']);
	$Kw = stripslashes($info['Kw']);
	$Hours = stripslashes($info['Hours']);
	$Price = stripslashes($info['Price']);

//create display string
$display_block = "
<table border = '1'> 
<td>".$ItemNo."</td>
<td>".$Man."</td>
<td>".$Cat."</td>
<td>".$Des."</td>
<td>".$Model."</td>
<td>".$Qty."</td>
<td>".$Kw."</td>
<td>".$Hours."</td>
<td>".$Price."</td>
</tr>
</table>";

//displays string with data
echo "$display_block";
}
?>

 

thanks in advacne

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/68398-solved-table-is-not-aligned-right/
Share on other sites

If you mean your columns are not aligning up it is because you are echo'ing a separate table for each row. You'll want to remove the table tags out of the loop:

<?php

//connect to database
include'db.php';

//get all data from table
$sql = "SELECT * from products";
$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));

$display_block = "<table border=\"1\">\n";

//if authorized, get the values
while ($info = mysqli_fetch_array($result))
{
    $ItemNo = stripslashes($info['Item_No']);
$Man = stripslashes($info['Manufacturer']);
$Cat = stripslashes($info['Category']);
$Des = stripslashes($info['Description']);
$Model = stripslashes($info['Model']);
$Qty = stripslashes($info['Qty']);
$Kw = stripslashes($info['Kw']);
$Hours = stripslashes($info['Hours']);
$Price = stripslashes($info['Price']);

//create display string
$display_block .= "  <tr>
    <td>".$ItemNo."</td>
    <td>".$Man."</td>
    <td>".$Cat."</td>
    <td>".$Des."</td>
    <td>".$Model."</td>
    <td>".$Qty."</td>
    <td>".$Kw."</td>
    <td>".$Hours."</td>
    <td>".$Price."</td>
  </tr>\n";
}

//displays string with data
echo $display_block . '</table>';
?>

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.