Tuesday, 11 February 2014

Dynamic Grid View In PHP

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
}


Create  a table of (table_name) with id and member_name

<?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$my_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")
        
$my_table .= '<tr><td>' $member_name '</td>';
    } else {
        
$my_table .= '<td>' $member_name '</td>';
    }
    
$i++;
}
$my_table .= '</tr></table>';?><html>
<body>
<h3>Dynamic PHP Grid Layout From a MySQL Result Set From PHP4allU</h3>
<?php echo $my_table?></body>
</html>

No comments:

Post a Comment

Thank your for your comment..your submitted coment will be live after admin approval