Jump to content

New to PHP, Need some help with a Table


Herzlos

Recommended Posts

Here is the code I am working on:

 

<?php

$table= "10_SEOW"; //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\">" ;

echo "<tr>" ;

 

//Table data

 

while (mysql_num_rows($num_rows) > 2) {

if ($row = mysql_fetch_array($num_rows)) {

print_r("<td class=\"odd\">" . $row . "/td" );

print_r("<td>" . $row . "/td" );

}

 

while (mysql_num_rows($num_rows) <= 2) {

if ($row = mysql_fetch_array($num_rows)) {

print_r("<td class=\"odd\">" . $row . "/td" );

print_r("<td>" . $row . "/td" );

}

 

while (mysql_num_rows($num_rows) < 2) {

if ($row = mysql_fetch_array($num_rows)) {

print_r("<td class=\"odd\">" . $row . "/td" );

}

 

 

//Table data

echo "</tr>";

echo "</tbody>";

echo "</table>";

?>

 

 

The code in Blue is working fine, just because its working doesn't mean I did it correct or the best way. So any advice to better my skills would be appreciated. I am having some issues figuring out what I need to do to get the table data area to work, I don't even think I am on the right path. :-\

 

I am trying to make it so I can use this code on several different pages, and only need to change the first line to fit the page its on.

 

Link to comment
https://forums.phpfreaks.com/topic/159739-new-to-php-need-some-help-with-a-table/
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.