Jump to content

Recommended Posts

hi can anyone help me make a seat map for this ? 
 

<form action="vars.php" method="post" class="niceform">
 <fieldset>
    	<legend>Velg / Valgt plass </legend>
        <dl>
        <?php
        $dato = ''.date('d.m.y');
/*
 * Created on Mar 13, 2007
 * Author: dayg
 */
	if (isset($_POST['seats']))
	{
		$user = $username;
	
		$newStatusCode = $_POST['newStatusCode'];
		$oldStatusCode = $_POST['oldStatusCode'];

		// open database connection
		$linkID = @ mysql_connect("localhost", "user", "pass") or die("Could not connect to MySQL server");
		@ mysql_select_db("DB_name") or die("Could not select database");

		// prepare select statement
		$selectQuery = "SELECT rowId, columnId from seats where (";
		$count = 0;
		foreach($_POST['seats'] AS $seat) {
			if ($count > 0) {
				$selectQuery .= " || ";
			}
			$selectQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
			$selectQuery .= " and columnId = " . substr($seat, 1) . " ) ";
			$count++;
		}
		$selectQuery .= " ) and status = $oldStatusCode";
		if ($oldStatusCode == 1) {
			$selectQuery .= " and updatedby = '$user'";
		}
		
		//echo $selectQuery;
		
		// execute select statement
		$result = mysql_query($selectQuery);
		//echo $result;
		
		$selectedSeats = mysql_num_rows($result);
		//echo "<br/>" . $selectedSeats;
		
		if ($selectedSeats != $count) {
			$problem = "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
			$problem .= "Possible problems are:";
			$problem .= "<ul>";
			$problem .= "<li>Another process was able to book the same seat while you were still browsing.</li>";
			$problem .= "<li>You were trying to Confirm an unreserved Seat.</li>";
			$problem .= "<li>You were trying to Cancel an unreserved Seat.</li>";
			$problem .= "<li>You were trying to Reserve a reserved Seat.</li>";
			$problem .= "<li>There was a problem connecting to the database.</li>";
			$problem .= "</ul>";
			$problem .= "<a href='seats.php'>View Seat Plan</a>";
			die ($problem);
		}
		
		// prepare update statement
		$newStatusCode = $_POST['newStatusCode'];
		$oldStatusCode = $_POST['oldStatusCode'];
		
		$updateQuery = "UPDATE seats set status=$newStatusCode, updatedby='$user' where ( ";
		$count = 0;
		foreach($_POST['seats'] AS $seat) {
			if ($count > 0) {
				$updateQuery .= " || ";
			}
			$updateQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
			$updateQuery .= " and columnId = " . substr($seat, 1) . " ) ";
			$count++;
		}
		$updateQuery .= " ) and status = $oldStatusCode";
		if ($oldStatusCode == 1) {
			$updateQuery .= " and updatedby = '$user'";
		}
		
		// perform update
		$result = mysql_query($updateQuery);
		$updatedSeats = mysql_affected_rows();

		if ($result && $updatedSeats == $count) {
			//$mysql->commit();
			echo "<h3>";
			echo "You have successfully updated $updatedSeats seat/s: ";
			echo "[";
			foreach($_POST['seats'] AS $seat) {
				$rowId = substr($seat, 0, 1);
				$columnId = substr($seat, 1);
				echo $rowId . $columnId . ", ";	
			}
			echo "]";
			echo "...</h3>";
		} else {
			//$mysql->rollback();
			echo "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
			echo "Possible problems are:";
			echo "<ul>";
			echo "<li>Another process was able to book the same seat while you were still browsing.</li>";
			echo "<li>You were trying to Confirm an unreserved Seat.</li>";
			echo "<li>You were trying to Cancel an unreserved Seat.</li>";
			echo "<li>You were trying to Reserve a reserved Seat.</li>";
			echo "<li>There was a problem connecting to the database.</li>";
			echo "<a href='seats.php'>View Seat Plan</a> </ br>";
			echo "</ul>";
		}
		
		echo "<dl>
        	<dt><label for='plass'>Din valgte plass:</label></dt>
            <dd><input type='text' name='plass' id='plass' value='$seat' readonly/></dd</dl>";
		
		// Enable the autocommit feature
		//$mysqldb->autocommit(TRUE);
		
		// Recuperate the query resources
		//$result->free();
		
		mysql_close();
	}
?>

i need to make something like the black image . now it is like the green image . 

post-167385-0-95678900-1391100647_thumb.png

post-167385-0-57860000-1391100742_thumb.png

Edited by stanghelle
Link to comment
https://forums.phpfreaks.com/topic/285804-php-seat-map/
Share on other sites


this is the right code for seat layout
<?php
/*
* Created on Mar 17, 2007
* Author: dayg
*/

$linkID = @ mysql_connect("localhost", "root", "root") or die("Could not connect to MySQL server");
@ mysql_select_db("hlan") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT rowId, columnId, status, updatedby from seats order by rowId, columnId asc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table width='500' border='0' cellpadding='3' cellspacing='3'>";
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != 'A') {
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table border='1' cellpadding='50' cellspacing='50'><tr height='50'>";
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = "lightgreen";
} else if ($status == 1 && $updatedby == 'user1') {
$seatColor = "FFCC99";
} else if ($status == 1 && $updatedby == 'user2') {
$seatColor = "FFCCFF";
} else if ($status == 2 && $updatedby == 'user1') {
$seatColor = "FF9999";
} else if ($status == 2 && $updatedby == 'user2') {
$seatColor = "CC66FF";
} else {
$seatColor = "red";
}

echo "\n<td bgcolor='$seatColor' align='center' width='50'>";
echo "$rowId$columnId";
if ($status == 0 || ($status == 1 && $updatedby == $_SERVER['PHP_AUTH_USER'])) {
echo "<input type='checkbox' name='seats[]' value='$rowId$columnId'></checkbox>";
}
echo "</td>";
if (($rowId == 'A' && $columnId == 7)
|| ($rowId == 'B' && $columnId == 7)
|| ($rowId == 'C' && $columnId == 7)
|| ($rowId == 'D' && $columnId == 7)
|| ($rowId == 'E' && $columnId == 7)
|| ($rowId == 'F' && $columnId == 7)
|| ($rowId == 'G' && $columnId == 7)
|| ($rowId == 'H' && $columnId == 7)
|| ($rowId == 'I' && $columnId == 7)
|| ($rowId == 'J' && $columnId == 7)
|| ($rowId == 'K' && $columnId == 7)
|| ($rowId == 'L' && $columnId == 13)
|| ($rowId == 'M' && $columnId == 9)) {
// This fragment is for adding a blank cell which represent the "center aisle"
echo "<td> </td>";
}
}

echo "</tr></table></td>";
echo "</tr>";
echo "</table>";

/* Close connection to database server. */
mysql_close();
?>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<table border="1" cellspacing="8" cellpadding="8">
<tr>
<td bgcolor='lightgreen'>Ledige sete</td>
<td bgcolor='red'>Reservert av bruker</td>
</tr>
</table>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<a href="seatplan.jpg" target="new"></a>
</td></tr>
</table>
</form>

 

Edited by stanghelle
Link to comment
https://forums.phpfreaks.com/topic/285804-php-seat-map/#findComment-1467102
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.