How would I keep the ID field from showing in the table..
Posted: Sun May 31, 2009 1:14 pm
Up till this point I was going to use a Part Number for the KeyID field. But some Items put into the DB rows won't have a Part Number so I need to use a Column as an ID field that will auto increment for my KeyID. I don't want the ID numbers to show in the Table that in printed to the website. I am hoping someone will know the answer to this as I have yet to figure it out but I am still looking for the answer.
Here is the code I have:
To sum it up, I am trying to figure out what I need to add to my code above to make it so the Table won't show the DB field of 'ID'. as 'ID' will be the only column I know every table will have.
Thanks for any help. I am sure this is a simple problem for most. As I am new to PHP I have yet to learn it.
Here is the code I have:
Code: Select all
<?php
//change to table name for page
echo "<table class=\"wire\" align=\"center\">";
echo "<thead class=\"wire1\">";
echo "<tr>";
$result = mysql_query("SHOW COLUMNS FROM $table");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
print_r("<th>" . $row[Field] . "</th>");
}
}
echo "</tr>";
echo "</thead>";
echo "<tfoot class=\"wire3\">";
echo "<tr>";
$qColumnNames = mysql_query("SHOW COLUMNS FROM $table",$connection) or die("mysql error");
$numColumns = mysql_num_rows($qColumnNames);
echo "<td colspan=\"$numColumns\">The data shown is approximate and subject to standard industry tolerances.</td>";
echo "</tr>";
echo "</tfoot>";
echo "<tbody class=\"wire2\">";
$data1 = mysql_query("SELECT * FROM $table", $connection);
$num_rows = mysql_num_rows($data1);
if (!$num_rows) {
die("database query failed: " . mysql_error());
}
while($num_rows >0){
if($num_rows >=2){
echo "<tr class=\"odd\">";
$data2 = mysql_fetch_array($data1, MYSQL_ASSOC);
foreach ($data2 as $rowdata)
{
print "<td> " . $rowdata . "</td>";
}
echo "</tr>";
$num_rows--;
echo "<tr>";
$data2 = mysql_fetch_array($data1, MYSQL_ASSOC);
foreach ($data2 as $rowdata)
{
print "<td> " . $rowdata . "</td>";
}
echo "</tr>";
$num_rows--;
}
elseif($num_rows =1){
echo "<tr class=\"odd\">";
$data2 = mysql_fetch_array($data1, MYSQL_ASSOC);
foreach ($data2 as $rowdata)
{
print "<td> " . $rowdata . "</td>";
}
echo "</tr>";
$num_rows--;
}
}
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "<br /> <br />";
?>
Thanks for any help. I am sure this is a simple problem for most. As I am new to PHP I have yet to learn it.