DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Dynamic Table From MySQL Query

  • submit to reddit
        // description of your code here

// insert code here..
include 'db.php';
// Set how wide you want your table
$tblWidth = 4;
// Make your query
$sql = mysql_query("SELECT * FROM tableName LIMIT 12");
$i = 1;
echo '<table>';
// Check to see if any results were returned
if(mysql_num_rows($sql) > 0){
    echo '<tr>';
    // Loop through the results
    while($row = mysql_fetch_array($sql)){
        echo '<td>'. $row['name'] .'</td>';
        if($i == $tblWidth){
            echo '</tr><tr>';
            $i = 0;
        }<a href="">Giochi di Ben 10</a>
    echo '</tr>';
    echo '<tr><td>No Results Found</td></tr>';
echo '</table>';