Hi Keith,
I'm really not sure what exactly it is that your are attempting to do with that blankarrayother than to initialize your other array data with all zeros with its values, but I have come up with a schema that should take care of all your requirements now.
First, I have come up with a database populator script that will build the basic structure of your database set aorund your seating criteria.
Next I have come up with a script that reads the data from the table based on a per row selection criteria. When run, I get the exact results that I believe that you are attempting to achieve.
Let me know if this helped.
CODE FOR DATABASE POPULATOR:
My database layout was as follows for this design;
DBName > seats
|
TABLE > tbl_seats
|
seatID ---------- auto_increment - Primary
seat_Row ----- int - Default 0
seat_Pos ------ int - Default 0
seat_Price ---- float (10,2) - Default 0.00
seat_Avail ---- int - Default 1 //1 = Avail - 0 = Booked
<?php
//replace this with your own code for database connection
include("db_inc.php");
$seat_Index = 1;
$seatLimits = array('A' => 17, 'B' => 18, 'C' => 9, 'D' => 9, 'E' => 9, 'F' => 9, 'G' => 9, 'H' => 9, 'I' => 9, 'J' => 9, 'K' => 9, 'L' => 9, 'M' => 9, 'N' => 9, 'O' => 9, 'P' => 9, 'Q' => 9, 'R' => 9, 'S' => 9, 'T' => 9, 'U' => 9);
// Row iteration loop
for($seatRow=1;$seatRow<=20;$seatRow++)
{
$seatAsciiVal = 64 + $seatRow;
// Array bound seat iteration loop that is bound to each row's limits
for($seatPos=1;$seatPos<=$seatLimits[chr(64+$seatRow)];$seatPos++)
{
$sql = "INSERT INTO `tbl_seats` (`seatID` , `seat_Row` , `seat_Pos` , `seat_Price` , `seat_Avail`) VALUES ('" . $seat_Index . "', '" . $seatAsciiVal . "', '" . $seatPos . "', '29.95', '1');";
$seat_Index += 1;
if(!($dbResult = mysql_query($sql, $db)))
{
print("ERROR: Could not retrieve data from query!<br>\n");
print("MySQL Reports: " . mysql_error() . "<br>\n");
exit();
}
}
}
print "New data has been successfully recorded to the database.\r\n";
?>
CODE FOR READING TABLE DATA AND DISPLAYING IT:
<?php
//replace this with your own code for database connection
include("db_inc.php");
$seatLimits = array('A' => 17, 'B' => 18, 'C' => 9, 'D' => 9, 'E' => 9, 'F' => 9, 'G' => 9, 'H' => 9, 'I' => 9, 'J' => 9, 'K' => 9, 'L' => 9, 'M' => 9, 'N' => 9, 'O' => 9, 'P' => 9, 'Q' => 9, 'R' => 9, 'S' => 9, 'T' => 9, 'U' => 9);
print "<table bgcolor=\"#3333CC\" align=\"center\">\r\n";
for($seatRow=1;$seatRow<=21;$seatRow++) //iterate through each row from A to U
{
$seatLtr = chr(64 + $seatRow);
print " <tr align=\"center\"><td colspan=\"" . $seatLimits[chr(64+$seatRow)] . "\" bgcolor=\"#999966\" align=\"center\">Row: " . $seatLtr . "</td></tr>\r\n";
print " <tr align=\"center\">\r\n";
print " <tr align=\"center\">\r\n";
//Here we are selecting only the records that correspond
//to each specific row throughout the iteration.
$sql = "SELECT seat_Row, seat_Pos, seat_Price, seat_Avail FROM tbl_seats WHERE seat_Row=" . ($seatRow + 64) . ";";
// performs the SQL statement upon the the database table
if(!($dbResult = mysql_query($sql, $db)))
{
print("ERROR: Could not retrieve data from query!<br>\n");
print("MySQL Reports: " . mysql_error() . "<br>\n");
exit();
}
//retrieves each row into an array called row whose
//array elements are called upon individually.
//Each row element contains the field key/value pairs that related to the read record.
while($row = mysql_fetch_array($dbResult))
{
print " <td width=\"3%\" align=\"center\" bgcolor=\"#CC99CC\">" . $row['seat_Pos'] . "</td>\r\n";
}
print " </tr>\r\n";
}
?>
I'm curious if this solves your problem. Good luck, Keith
π
~Adrian