kingpoiuy
May 5th, 2008, 03:46 PM
Hello, I am trying to display a table from MySQL on a web page using PHP. For some reason my table is creating extra <td>'s. It seems that i can select all the column's and it will display fine but if I skip the 'user' column then the next column after that is blank. I can post screenshots if necessary. Here is my PHP website code.
<?php
include 'config.php';
include 'opendb.php';
include 'serialdbindex.php';
$query = "SELECT ";
echo "<table border='1' align='center'>";
echo "<tr>";
echo "<td><b>Computer</b></td>";
if($_POST['user'] == 'on')
{
$query .= "user, ";
echo "<td><b>User</b></td>";
}
if($_POST['windows'] == 'on')
{
$query .= "windows, ";
echo "<td><b>Windows</b></td>";
}
if($_POST['office'] == 'on')
{
$query .= "office, ";
echo "<td><b>Office</b></td>";
}
if($_POST['antivirus'] == 'on')
{
$query .= "antivirus, ";
echo "<td><b>Anti-Virus</b></td>";
}
if($_POST['description'] == 'on')
{
$query .= "description, ";
echo "<td><b>Description</b></td>";
}
echo "</tr>";
$query .= "computer FROM main ORDER BY computer";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['computer'] . "</td>";
echo "<td>" . $row['user'] . "</td>";
echo "<td>" . $row['windows'] . "</td>";
echo "<td>" . $row['office'] . "</td>";
echo "<td>" . $row['antivirus'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "</tr>";
}
echo "</table>";
/*
echo "<pre>";
echo $query;
echo "</pre>";
*/
include 'closedb.php';
?>
Thank you for looking.
<?php
include 'config.php';
include 'opendb.php';
include 'serialdbindex.php';
$query = "SELECT ";
echo "<table border='1' align='center'>";
echo "<tr>";
echo "<td><b>Computer</b></td>";
if($_POST['user'] == 'on')
{
$query .= "user, ";
echo "<td><b>User</b></td>";
}
if($_POST['windows'] == 'on')
{
$query .= "windows, ";
echo "<td><b>Windows</b></td>";
}
if($_POST['office'] == 'on')
{
$query .= "office, ";
echo "<td><b>Office</b></td>";
}
if($_POST['antivirus'] == 'on')
{
$query .= "antivirus, ";
echo "<td><b>Anti-Virus</b></td>";
}
if($_POST['description'] == 'on')
{
$query .= "description, ";
echo "<td><b>Description</b></td>";
}
echo "</tr>";
$query .= "computer FROM main ORDER BY computer";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['computer'] . "</td>";
echo "<td>" . $row['user'] . "</td>";
echo "<td>" . $row['windows'] . "</td>";
echo "<td>" . $row['office'] . "</td>";
echo "<td>" . $row['antivirus'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "</tr>";
}
echo "</table>";
/*
echo "<pre>";
echo $query;
echo "</pre>";
*/
include 'closedb.php';
?>
Thank you for looking.