Jump to content

pizote

New Members
  • Posts

    5
  • Joined

  • Last visited

pizote's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you! Creating the column[] and then populating it seemed to do the trick. The <tr> tags was discovered and corrected previously. FYI - this allows me to have one edit/add page for a multitude of lookup tables. I have a menu that is auto-generated so any time I add a lookup table, it populates the menu. The link sends a POST to the table listing, which generates the table header and table body based on the $_GET. Each row is then linked to a single edit/add page. Three images: Dynamic Menu - generated from the TABLE_COMMENT for table names that match a pattern Dynamic table list #1 Dynamic table list #2 Now to create the add/edit pages
  2. Here's the code and results: function getTableColumns($lu_tableName) { $columns = ""; $sqlSelect = "SELECT COLUMN_NAME, COLUMN_COMMENT"; $sqlFrom = "FROM information_schema.columns"; $sqlWhere = "WHERE table_name = '$lu_tableName'"; $sqlOrder = ""; $columns = sqlCall($sqlSelect,$sqlFrom,$sqlWhere,$sqlOrder); return $columns; } function getLuTableData($lu_tableName) { $data=""; $sqlSelect = "SELECT *"; $sqlFrom = "FROM $lu_tableName"; $sqlWhere = ""; $sqlOrder = ""; $data = sqlCall($sqlSelect,$sqlFrom,$sqlWhere,$sqlOrder); return $data; } function getLuTableBody($lu_tableName) { $tableBodyHtml =""; $tableColumns=getTableColumns($lu_tableName); $tableData=getTableData($lu_tableName); if ($tableData->num_rows > 0) { while($row = $tableData->fetch_assoc()) { if ($tableColumns->num_rows > 0) { while($column = $tableColumns->fetch_assoc()) { $columnName=$column['COLUMN_NAME']; $tableBodyHtml .= "<td>$row[$columnName]</td>"; } } else { echo "problem with column data"; } } } else { echo "problem with record data"; } return $tableBodyHtml; }
  3. I’ll load the code in a bit. both functions work and return their proper data. The getColumnTables() returns the column table names. The getTableData() returns all data for the table. the nested while statements are what’s picking at me. The current code returns proper headers. And proper data - for one row. if I reverse the while statements, I was getting still only one row, but with one record id for each column.
  4. Thank you Maxxd - that solves the duplicate <td>, but it still doesn't resolve that only one record of $tableData is being returned. Still stumped on that one.
  5. I am trying to dynamically create a form where I pass a table name and it presents me with a table of all the columns (varying number and names of columns) into an HTML table. Both of my queries are working, but for some reason, my nested while statements are not working. Any ideas? function getLuTableBody($lu_tableName) { $tableBodyHtml =""; $tableColumns=getTableColumns($lu_tableName); $tableData=getTableData($lu_tableName); if ($tableData->num_rows > 0) { while($row = $tableData->fetch_assoc()) { if ($tableColumns->num_rows > 0) { $tableBodyHtml .= "<tr>"; while($column = $tableColumns->fetch_assoc()) { $columnName=$column['COLUMN_NAME']; $tableBodyHtml .= "<td>$row[$columnName]<td>"; } $tableBodyHtml .= "</tr>"; } else { echo "problem with column data"; } } } else { echo "problem with record data"; } return $tableBodyHtml; } Here's the contents of the db id bundleRole recordStatus 1 Database A 2 Web A 3 Base A 4 Application A 5 Print A Here's the output <table id="advanced_table" class="table dataTable"> <thead> <tr> <th>Record ID</th> <th>Bundle Role</th> <th>Record Status</th></tr> </thead> <tbody> <tr> <td>1</td> <td></td> <td>Database</td> <td></td> <td>A</td> <td></td> </tr> </tbody> </table>
×
×
  • 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.