Note that there are some explanatory texts on larger screens.

plurals
  1. PODefining HTML tables within PHP
    primarykey
    data
    text
    <p>I'm trying to get an HTML Table output in to a specific format via PHP after it grabs information from a MySQL Database.</p> <p>In HTML, I can do this:</p> <pre><code>&lt;table cellpadding="0" cellspacing="0" class="list"&gt; &lt;tr&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name1'"&gt;Name1&lt;/td&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name2'"&gt;Name2&lt;/td&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name3'"&gt;Name3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name4'"&gt;Name4&lt;/td&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name5'"&gt;Name5&lt;/td&gt; &lt;td style="cursor:hand" onclick="window.location.href = 'page.php?presenter=Name6'"&gt;Name6&lt;/td&gt; &lt;/table&gt; </code></pre> <p>This works great and looks nice, I have it DIV'd up and formatting nicely.</p> <p>However, I need to do this by pulling down the names from MySQL and then creating a new cell when needed, then after 3 cells, create a new row.</p> <p>So far, I have this:</p> <pre><code>&lt;?php //PRESENTERS HERE /* connect to the db */ $connection = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($db, $connection); /* show tables */ $result = mysql_query('SHOW TABLES', $connection) or die('cannot show tables'); echo '&lt;h1&gt;Presenters:&lt;/h1&gt;'; while ($tableName = mysql_fetch_row($result)) { $table = 'presenters'; /* Get the presenters*/ $result2 = mysql_query('SELECT presenter FROM ' . $table) or die('cannot show data from ' . $table); } if (mysql_num_rows($result2)) { echo '&lt;table cellpadding="0" cellspacing="0" class="list"&gt;'; while ($row1 = mysql_fetch_row($result2)) { echo '&lt;tr&gt;'; foreach ($row1 as $key =&gt; $value) { echo '&lt;td style="cursor:hand" onclick=\"window.location.href = \'page.php?presenter=' . $value . '"&gt;', $value, '&lt;/td&gt;'; } echo '&lt;/tr&gt;'; } echo '&lt;/table&gt;&lt;br /&gt;'; } ?&gt; </code></pre> <p>But I'm unable to figure out how to get it to behave like the HTML one above. I also can't get the on click events to work.</p> <p>The PHP form ends up with all entries on a row each, instead of three to a row.</p>
    singulars
    1. This table or related slice is empty.
    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