Dynamic Grid Output Programming Tutorial Using PHP + MySQL Array Data

Dynamic Grid Output Programming Tutorial Using PHP + MySQL Array Data

Listening Video

When accessing database or any dynamic array of information you can apply this method to produce a grid layout instead of a traditional linear layout. You can use tables, divs, or simple line breaks as a stagger mechanism.

Most times an HTML <table> is used to make a grid of table rows and columns from a dynamic array of information. But you are not limited to tables, use DIVs with "display:inline" applied in their CSS, or any other container tag that can hold text and stuff on a web page.

This video is accompanied by this copy + paste script: http://sh.st/aqiGI

The raw logic of the script below is:
if ( my loop's increment number is divisible by my specified number ) {
    // Break line, make new table row, or any code that breaks my normal linear display
} else {
    // Normal display code for continuing linear display
}

Learn HTML
<?php// Include database connectioninclude_once 'connect_to_mysql.php';// SQL query to interact with info from our database$sql mysql_query("SELECT id, member_name FROM member_table ORDER BY id DESC LIMIT 15"); $i 0;// Establish the output variable$dyn_table '<table border="1" cellpadding="10">';
while(
$row mysql_fetch_array($sql)){
   
    
$id $row["id"];
    
$member_name $row["member_name"];
   
    if (
$i == 0) { // if $i is divisible by our target number (in this case "3")
        
$dyn_table .= '<tr><td>' $member_name '</td>';
    } else {
        
$dyn_table .= '<td>' $member_name '</td>';
    }
    
$i++;
}
$dyn_table .= '</tr></table>';?><html>
<body>
<h3>Dynamic PHP Grid Layout From a MySQL Result Set</h3>
<?php echo $dyn_table?></body>
</html>


Develop PHP browser display window

Dynamic PHP Grid Layout From a MySQL Result Set

polmikethomassmallspaceship
tomik1963ownlink2010rajkumarpdr
johnmcleroyjwilbertkashif619
StribtechDjRowdyginaty05
Kyuredarkrai003strohnna

0 Response to "Dynamic Grid Output Programming Tutorial Using PHP + MySQL Array Data"

Post a Comment