Jump to content


Seatmap | Help


2 replies to this topic

#1 Zetra

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 02 July 2007 - 08:46 AM

Hello,

Im working on a seatmap for a LAN site, and I need help with the color change in the box.

www.samlan.no/seat/ <-- The seatmap.

Room.php
<table width="400" cellpadding="10" cellspacing="0" id="1" border="1" bordercolor="#000000" rules="all">
  <tr>
	<td width="16" id=1 class="green"><a href="seat.php?id=1">1</a></td>
	<td width="16" id=2 class="green"><a href="seat.php?id=2">2</a></td>
</tr>
</table>

I need a code that changes the class to red if someone has reserved the seat.

Ledig.php:
<?php

include "config.php";

$hent = mysql_query("SELECT color FROM reg WHERE id = '$_GET[id]'");

echo ("$color");

?>

Help please. :lol:

Edited by Zetra, 02 July 2007 - 05:55 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 02 July 2007 - 11:06 AM

Simple really.
I don't know how your database is structured, but it would work just like this.

<?php

include 'config.php';
echo '<table width="400" cellpadding="10" cellspacing="0" id="seat_table" border="1" bordercolor="#000" rules="all">';
echo "\n<tr>";

$query = mysql_query("SELECT `seat_id`, `taken` FROM `seats`") or die(mysql_error());

while($seat = mysql_fetch_array($query))
  echo "\n".'<td with="16" id="seat_'.$seat['seat_id'].'" class="'.($seat['taken'] == 0 ? 'green' : 'red').'"><a href="seat.php?id='.$seat['seat_id'].'">'.$seat['seat_id'].'</a></td>';

echo "\n</tr>\n</table>";

?>

Again, I don't know exactly how your database is structured, but I assume you can edit the query and display how you need, such as making new rows after so many cells.

The basic concept is, in your database, you have a `taken` column in with your `seats` table. If it is '0', it is not taken. Conversely, if it is not 0, it is taken. Based on this column, you can echo which color class to give it.

#3 Zetra

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 02 July 2007 - 05:47 PM

This is my databasen:
CREATE TABLE `reg` (
`id` int(10) NOT NULL auto_increment,
`color` varchar(255) NOT NULL default '',
`name` varchar(255) NOT NULL default '',
`seat` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

Seat.php:
<?php
include "room.php";
include "config.php";

$id = $_GET['id'];
$hent = mysql_query("SELECT * FROM reg WHERE seat = '$id'");
if (mysql_num_rows($hent) == "0") {

echo ("<br /><a href='velg.php?id=$id'><b>This seat is free.</font><br />
Sit here</a>");

}

while($r=mysql_fetch_array($hent)) { 

$seat = $r['seat'];
$name= $r['name'];

echo ("<br /><b>This seat is taken!<br />$name is sitting here.</b>");
}
?>

Room.php :
<table width="400" cellpadding="10" cellspacing="0" id="1" border="1" bordercolor="#000000" rules="all">
  <tr>
	<td width="16" id=1 class="<?php include("ledig.php?id=1"); ?>"><a href="seat.php?id=1">1</a></td>
	<td width="16" id=2 class="<?php include("ledig.php?id=2"); ?>"><a href="seat.php?id=2">2</a></td>

	<td width="16" id=3 class="<?php include("ledig.php?id=3"); ?>"><a href="seat.php?id=3">3</a></td>
	<td width="16" id=4 class="<?php include("ledig.php?id=4"); ?>"><a href="seat.php?id=4">4</a></td>
	<td width="16" id=5 class="<?php include("ledig.php?id=5"); ?>"><a href="seat.php?id=5">5</a></td>
	<td width="16" id=6 class="<?php include("ledig.php?id=6"); ?>"><a href="seat.php?id=6">6</a></td>
	<td width="16" id=7 class="<?php include("ledig.php"); ?>"><a href="seat.php?id=7">7</a></td>
	<td width="16" id=8 class="<?php include("ledig.php"); ?>"><a href="seat.php?id=8">8</a></td>

	<td width="16" id=9 class="<?php include("ledig.php"); ?>"><a href="seat.php?id=9">9</a></td>
	<td width="16" id=10 class="<?php include("ledig.php"); ?>"><a href="seat.php?id=10">10</a></td>
  </tr>
</table>

Velg.php: (or in english pick.php)
<?php 
include("config.php"); 

if ($_POST[register]) { 
$seat = $_POST[seat]; 
$name = $_POST[name]; 
$color = $_POST[color]; 
if($seat==NULL|$name==NULL|$color==NULL) { 
echo "You forgot somethinge.";
} else { 

$checkid = mysql_query("SELECT seat FROM reg WHERE seat='$seat'"); 
$checkid= mysql_num_rows($checkid);  
if ($checkid>0) { 
echo "This seat is taken!"; 

} else {

$checkname = mysql_query("SELECT name FROM reg WHERE name='$name'"); 
$checkname= mysql_num_rows($checkname);  
if ($checkname>0) { 
echo "Your name is already registered!"; 

} else {

$seat = htmlspecialchars($seat); 
$name = htmlspecialchars($name); 
$color = htmlspecialchars($color); 
$query = mysql_query("INSERT INTO reg (seat, name, color) VALUES('$seat','$name','$color')"); 
echo "Your seat is reserved."; 
} 
} 
} 
} else {

$id = $_GET['id'];
echo (" <form method='POST'>
Is this correct?<br />
Seat: <input type='text' size='30' name='seat' value='$id'><br />
Name: <input type='text' size='30' name='name'><br />
<input type='hidden' name='color' value='taken'>
<input name='register' type='submit' class='text' value='Submit'>
</form>"); 
} 
?>

Edited by Zetra, 02 July 2007 - 06:01 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users