Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically generate html table with php of mysql records
    primarykey
    data
    text
    <p>The reason this is complicated (for me) is that each column of the table is loaded from a separate MySQL table, and each MySQL table will have varying number of records. Initially I thought I could start generating the html table from top-left to bottom-right column by column , cell by cell, but this won't work because each MySQL table will have different length of records, which generate malformed html tables. Do you have any suggestions?</p> <p>My idea so far: </p> <ul> <li>Get a list of all tables in MySQL, which determine the number of columns </li> <li>Get the count from the table with most records</li> <li>Create a table with the parameters (# of tables as columns, max# as rows</li> <li>Update each cell with the corresponding record, but not quite sure how</li> </ul> <p>As requested, some code: </p> <pre><code>$tables = mysql_query("show tables"); $output = "&lt;table border=1&gt;&lt;thead&gt;&lt;tr&gt;"; while($table = mysql_fetch_array($tables)) { $output .= "&lt;td&gt;"; $output .= $table[0]; $output .= "&lt;/td&gt;"; $tableNames[] = $table[0]; } $output .= "&lt;/tr&gt;&lt;/thead&gt;"; $output .= "&lt;tbody&gt;"; //Get a count of the table with the most records for($i=0; $i&lt;count($tableNames); $i++ ){ $currentTable = $tableNames[$i]; $tableContent = mysql_query("select * from $currentTable") or die("Error: ".mysql_error()); //Generating all content for a column $output .= "&lt;tr&gt;"; while($content = mysql_fetch_array($tableContent)){ //generating a cell in the column $output .= "&lt;td&gt;"; $output .= "&lt;strong&gt;".$content['subtheme'].": &lt;/strong&gt;"; $output .= $content['content']; $output .= "&lt;/td&gt;"; } $output .= "&lt;/tr&gt;"; } $output .= "&lt;/tbody&gt;"; $output .= "&lt;/table&gt;"; </code></pre> <p>This is wrong not just because it generates a malformed table, but also because it transposed columns to rows...</p> <p>Any help would be appreciated</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload