Herzlos Posted May 26, 2009 Share Posted May 26, 2009 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 More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 1. Please don't color-coordinate your code. Use or tags instead. 2. Is $num_rows defined? 3. I sure hope the value of $num_rows change in your while loop or it'll be an infinite loop. Link to comment https://forums.phpfreaks.com/topic/159739-new-to-php-need-some-help-with-a-table/#findComment-842553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.