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
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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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