I have created a table that is dynamically populated from a MySQL database using PHP. The first row is a repeated region for all records. However is it possible to have a minimum number of rows created whether there was a record or not. For example if I have 8 records for a given date could the table be drawn with 12 rows regardless, 4 of them will just be empty?
Asked
Active
Viewed 534 times
1 Answers
0
Firstly, good design separates retrieval and data model from display (MVC)
$data = array();
$result = $db->query("SELECT * FROM table");
while($row = $result->fetch_assoc()) {
$data[] = $row;
}
Now you just do
$MIN_VALUE = 12; // Some value
$i = 0;
foreach($data as $row) {
//Data row
$i++;
}
while(!$i < $MIN_VALUE) {
//Blank row
$i++;
}

Philip Whitehouse
- 4,293
- 3
- 23
- 36
-
i appreciate your response. I've been toying around with something similiar but couldnt get it to work....where in the loop would you create the table row that is repeated? where u have // data row? – Dean Jan 01 '13 at 01:43
-
If you want a row repeated after every row, put it in the `foreach`. If you want it before that, put it before the `foreach`. If you want it once per blank row, put it in the `while` – Philip Whitehouse Jan 01 '13 at 02:06
-
this is my query..........mysql_select_db($database_#####, $#####); $query_RsManifest = "SELECT * FROM manifest WHERE TripinfoID = ###"; $RsManifest = mysql_query($query_RsManifest, $####) or die(mysql_error()); $row_RsManifest = mysql_fetch_assoc($RsManifest); $totalRows_RsManifest = mysql_num_rows($RsManifest); – Dean Jan 01 '13 at 02:41
-
would anybody care to add to this?... i've tried this a 100 different ways and i cannot seem to get any where – Dean Jan 07 '13 at 22:34