Page 1 of 1
Dynamically Generate Grid from Results
Posted: Sat Apr 03, 2010 6:48 pm
by hwdesign
I've run an MySQL query that returns an array of square thumbnails. I want to dynamically display the results in 3x3 grids sort of like this:
Code: Select all
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
I was thinking I could float three unordered lists next to each other, then wrap each set of three in a div and float the div. However, I'm stumped on how to do this dynamically.
Any help would be greatly appreciated.
Re: Dynamically Generate Grid from Results
Posted: Sat Apr 03, 2010 9:14 pm
by Architek
I typically do this in a table...
here is an example of what I have done via table output.
Code: Select all
<div id="order-query-report">
<table>
<tr id="query-report-labels">
<td class="head-county">County</td>
<td class="head-username">Created By</td>
<td class="head-datetime">Date Created</td>
<td class="head-submit-status" span="1">Submit Status</td>
<td class="head-ico"></td>
<td class="head-username">Submitted By</td>
<td class="head-datetime">Date Submitted</td>
<td class="head-formtype" span="1">Form Type</td>
<td class="head-ico2"></td>
</tr>
<?php
//Make SQL Request
$query = "SELECT [instance]
,[ordernumber]
,[usernamesave]
,[datesave]
,[propcounty]
,[submitstatus]
,[usernamesubmit]
,[datesubmit]
,[formtype]
FROM [$db_name1].[dbo].[$tbl_name1]";
if($ordernumber > "" and $datefilter > ""){$query .= " WHERE [ordernumber] = '".$ordernumber."' AND CONVERT(nvarchar(30), datesave, 110) like '%".$datefilter."%'";}
if($ordernumber == "" and $datefilter > ""){$query .= " WHERE CONVERT(nvarchar(30), datesave, 110) like '%".$datefilter."%'";}
if($ordernumber > "" and $datefilter == ""){$query .= " WHERE [ordernumber] = '".$ordernumber."'" ;}
$result = sqlsrv_query($conn, $query);
while($rows = sqlsrv_fetch_array($result)){
?>
<tr>
<form action="<?php echo "ereet-query-".$rows['formtype'].".php"; ?>" method="post" id="queryform" name="queryform" target="_blank" >
<input type="hidden" name="instanceid" value="<?php echo $rows['instance']; ?>"></input>
<input type="hidden" name="ordernumber" value="<?php echo $rows['ordernumber']; ?>"></input>
<td >
<?php echo $rows['propcounty']; ?> 
</td>
<td >
<?php echo $rows['usernamesave']; ?> 
</td>
<td>
<?php @$datesave = date_format($rows['datesave'], "m/d/Y h:i");
echo $datesave; ?> 
</td>
<td>
<?php if($rows['submitstatus'] == 2){echo "Pending</td><td class=\"ico-noborder-lft\"><img src=\"images/aqua.png\" />";}
if($rows['submitstatus'] == 0){echo "Processing</td><td class=\"ico-noborder-lft\"><img src=\"images/yellow.png\" />";}
if($rows['submitstatus'] == 3){echo "Complete</td><td class=\"ico-noborder-lft\"><img src=\"images/green.png\" />";} ?> 
<td>
<?php echo $rows['usernamesubmit']; ?> 
</td>
<td>
<?php @$datesubmit = date_format($rows['datesubmit'], "m/d/Y h:i");
echo $datesubmit; ?> 
</td>
<td>
<?php if($rows['formtype'] = "standard"){$formname = "Standard Form";}
if($rows['formtype'] = "mobilehome"){$ormname = "Mobile Home Form";}
if($rows['formtype'] = "supplemental"){$formname = "Supplemental Form";}
if($rows['formtype'] = "controlling"){$formname = "Controlling Interest Form";}
if($formname > ""){echo $formname. "</td><td class=\"ico-noborder-lft\"><input type=\"image\" src=\"images/preview.png\" name=\"viewformquerys\" class=\"query-view-button\" value=\"\"></input>";}?> </td>
</form>
</tr>
<?php
}
//close database
sqlsrv_close($conn);
}
?>
</table>
</div>
Re: Dynamically Generate Grid from Results
Posted: Sun Apr 04, 2010 12:13 am
by hwdesign
Thanks for the example.
I found this to work a little better in my situation:
Code: Select all
$setCount = 0; // counter that keeps track of each set of scrolling lenses
$count = 0; // counter that keeps track of the lens we are up to in the list
while($row = mysql_fetch_array($r)){
$setCount++;
$count++;
if($setCount == 1) { // each time we start a new set
echo "<ul class='mySet'>
";
}
//...
// WRITE your LI TAGS HERE...
//...
if($setCount == 9 && $count < $totalNum) {
// if we have reached our 9th item in the set and we aren't at the end of the list...
echo "</ul>
";
$setCount = 0;
} else if($count == $totalNum) { // if we've reached the last item in the list...
echo "</ul>
";
}
}
Re: Dynamically Generate Grid from Results
Posted: Sun Apr 04, 2010 12:30 am
by Architek
yea that is a mutch better way to handle that one.