MySQL Forums
Forum List  »  PHP

Re: Display column contents in html table with PHP
Posted by: Barry Galbraith
Date: August 21, 2012 07:40PM

Something like this?

<?php

mysql_connect('localhost', 'username', 'password');
mysql_select_db('mydatabase');

$sql = "SELECT categoria FROM categorias_tbl";
$result = mysql_query($sql);

//echo "<select name='categoria'>";
echo "<form action=\"#\">"; //Must have a form if you want to display inputs
echo "<table>"; //begin a table for your display
$cnt = 0;  // <td> counter
while ($row = mysql_fetch_array($result)) {
if ($cnt % 3 == 0) { //even multiple of 3 <td>
	echo "<tr>";
	}
echo "<td><input type='checkbox' name=\"categoria\" value=\"{$row['categoria']}\" />{$row['categoria']}</td>";
++$cnt; // increment the <td> counter
}
while ($cnt % 3 != 0) {
	// fill any leftover <td> to balance the table
	echo "<td>&nbsp;</td>";
	++$cnt;
	}
echo "</table>";  // close the table
echo "</form>";  // close the form
?>

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Display column contents in html table with PHP
August 21, 2012 07:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.