Jump to content

Script idea help


lee2010

Recommended Posts

Hi all, i want to write seating plan page, i want it to work by having the logged in user click on a link or image and the system will mark that users username into that seat.

 

I have everything working in terms of the log in but as far as this page goes i really have no idea how i would start with it. If your not sure what i mean i can put it this way to make it much more understandable.

 

If my page had the numbers 1 through to 49 listed down the side and next to each number it says as default "availible", but if the user click on that number the text next to that number changes from "availible" to the users username and no one others can click on that number as its "seat" or "number" has been taken.

 

My users are stored within a mysql database and my site uses sessions like so:

 

$_SESSION[username] = $row[username]; 

 

Many thanks for your help

Link to comment
Share on other sites

Perhaps...

ie

1. initially populate an html with either a link to a process script (via GET);  OR if seat is taken, no link just the name of person in that seat.

2. process script updates db seat_taken table with user's id/name/etc, then advises user their seat is reserved.

 

Link to comment
Share on other sites

hi,

 

so i could have the seat number as a hyperlink to the script which stores the number they have selected with there username, so if i had 49 seats would this mean i would need 49 different process scripts (process_1.php -> process_49.php for example) or would there be a simplier way of doing this?

Link to comment
Share on other sites

hi,

 

so i could have the seat number as a hyperlink to the script which stores the number they have selected with there username, so if i had 49 seats would this mean i would need 49 different process scripts (process_1.php -> process_49.php for example) or would there be a simplier way of doing this?

 

Yes, the way I suggested...

Link to comment
Share on other sites

so your saying like this@

 

Seat 1 - Availible <hyperlink to seat_1.php>

Seat 2 - <users username that has taken it>

Seat 3 - Availible <hyperlink to seat_3.php>

 

seat_1.php updates my seating database with seat number 1 with the username of the user that clicked it.

 

Im thinking of getting it to pull the username from each seat with a echo row and if its empty (eg. no user has chosen that seat) then it shows the link to select it for yourself.

 

does this seem right or is there a better way of doing it?

 

Lee

Link to comment
Share on other sites

VERY rough example (only showed code for first 2 seats to give idea what is happening)...

 

the display seating chart page...

<?PHP
session_start();
/* get user id */
$user_id = $_SESSION['user_id'];
/* connect to data base */
include('db.php');

/* proposed seats_table structure */
/* id, user_id (INT) , taken (TRUE/FALSE) */
/* table has 49 rows - row 1 represents seat 1, row 2 seat 2 etc etc */
/* initially user_id = 0 and taken = FALSE */

/* create query */
$query = "SELECT * from seats_table";

/* execute query */
$result = mysql_query($query);

/* get the results and put them into an array */
while($row = mysql_fetch_array($result)){
$seat_status[] = $row['taken'];
}

/* display the data in a table */
?>
<table>
<tr>
	<td >Seat 1<br/>
		<?PHP
		if(!seat_status[0]){ 
			echo "taken"; 
		}else{
			?>
			<a href="reserve_seat.php?seat=1">Available</a>
			<?PHP
		}
		?>
	</td>
	<td >Seat 2<br/>
		<?PHP
		if(!seat_status[1]){ 
			echo "taken"; 
		}else{
			?>
			<a href="reserve_seat.php?seat=2">Available</a>
			<?PHP
		}
		?>
	<td >Seat 3</td>
	<td >Seat 4</td>
	<td >Seat 5</td>
	<td >Seat 6</td>
	<td >Seat 7</td>
</tr>
</table>

 

the reserve_seat.php page...

<?PHP
session_start();
/* get user id */
$user_id = $_SESSION['user_id'];

/* get the seat number */
$seat_id = $_GET['seat'];

/* connect to data base */
include('db.php');

/* create query */
$query = "UPDATE seats_table set taken = TRUE, user_id = '$user_id'  WHERE id = '$seat_id'";

/* execute the query */
$result = mysql_query($query);

/* advise user their seat has been reserved */

Link to comment
Share on other sites

hi, im getting this error:

 

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\seating.php on line 60

 

heres my code:

 

<?php
  $user_id = $_SESSION['username'];
/* connect to data base */
require ('./secure/connect.php');

/* proposed seats_table structure */
/* id, user_id (INT) , taken (TRUE/FALSE) */
/* table has 49 rows - row 1 represents seat 1, row 2 seat 2 etc etc */
/* initially user_id = 0 and taken = FALSE */

$query = "SELECT * from seats_table";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){
$seat_status[] = $row['taken'];
}


/* display the data in a table */

?>
<table>
	<tr>
	<td >Seat 1 - </td><br/>

		<?PHP

			if(!seat_status[0]){
			echo "Seat Taken";
			}
			else{
			?>
			<a href="reserve_seat.php?seat=1">Availible</a>

			<?PHP } ?>
			</tr>

			<tr>


</table>

 

line 60 is this particluar line:

 

if(!seat_status[0]){

Link to comment
Share on other sites

1. sessions are not started in the code shown

2. you table tags are in error

this...

<table>
<tr>
	<td >Seat 1 - </td><br/>
		<?PHP
		if(!seat_status[0]){
			echo "Seat Taken";
		}else{
		?>
			<a href="reserve_seat.php?seat=1">Availible</a>
		<?PHP 
		}
		?>
</tr>
<tr>
</table>

should be this..

<table>
<tr>
	<td >Seat 1 - <br/>
		<?PHP
		if(!$seat_status[0]){
			echo "Seat Taken";
		}else{
		?>
			<a href="reserve_seat.php?seat=1">Availible</a>
		<?PHP 
		}
		?>
	</td>
</tr>
<tr>
</table>

 

 

Link to comment
Share on other sites

ok i have it working now but theres a few problems.

 

i would like it so next to the seat a user picks it displays the username of the person that has taken it, opposed to just seat taken. my current code for this is:

 

<?php
			if ($seat_status[0]){
			echo "Seat Taken";
		}
		else{
			?>
			<a href="reserve_seat.php?seat=1">Availible</a>
			<?php } ?>

 

I would like for it to echo out the username, so it would say "Seat taken by <there username>"

 

 

Also if a user choses a seat then decides to choose another seat the old one is still marked as taken with there username shown for it in the database, i need a script that will check if the user already has a seat and clears it before showing them on another seat.

 

Thanks alot if you can help me on this, but apart from these 2 points its working fine :)

Link to comment
Share on other sites

ok after a bit of work i have the second part i listed above working, users can swap between seats all they like and there previous seats are wiped clean with this code:

 

$query2 = "UPDATE seats_table set taken = FALSE, user_id = '0' WHERE user_id = '$user_id'";

 

before updating there new seat  :D

 

still need a bit of help shhowing the username opposed to just "seat taken"

Link to comment
Share on other sites

New to this forum and new to PHP. (I have programmed extensively using Perl)

 

It seems that the code proposed is going to get totally out of hand if more than a very few seats are included.

Instead, I would propose...

 
<?php
echo "<table>\n<tr>\n";
$no = 1;
$query = "SELECT * from seats_table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
    $status = ($row['taken']) ? "Taken by $row[username]" : '<a href="reserve_seat.php?seat='.$no.'">Available</a>'; 
    echo "<td>Seat $no<br/>$status</td>\n";
    $no++;
echo "</tr>\n<\table>\n";
?>

I added the username assuming that it is included in 'seats_table'

 

I do, however, have a question.

Is there some reason that the original code is broken up into little PHP snippets?

Why not include the whole table within the PHP tags and echo the lines?

Link to comment
Share on other sites

hi thanks for your reply, i just wanted to get it working before i got down to tidying it up etc, so no there wasnt a real reason for it :shy:

 

just tried your code and im getting this error:

 

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\seating.php on line 87

 

heres my code:

 

<?php require ("admin/seating-auth.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SouthWest LAN's</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
</head>
<body>
<!-- Begin Wrapper -->
<div id="wrapper">
  <!-- Begin Header -->
  <div id="header"><h1><br />SouthWest LAN's</h1></div>
  <!-- End Header -->
  <!-- Begin Navigation -->
  <div id="navigation"><ul>
            <li style="margin-right:15px; display:inline;"><a href="index.php">Home</a></li>
		<li style="margin-right:15px; display:inline;"><a href="gallery/">Photo Gallery</a></li>
		<li style="margin-right:15px; display:inline;"><a href="events.php">Events</a></li>
		<li style="margin-right:15px; display:inline;"><a href="account.php">My Account</a></li>
		<li style="margin-right:15px; display:inline;"><a href="forum.php">Forums</a></li>
		<li style="margin-right:15px; display:inline;"><a href="faq.php">FAQ</a></li>
		</ul></div>
  <!-- End Navigation -->
  
  <!-- Begin Content Column -->
    <div id="content">
      <h1>Seating</h1><br />
      <p>
  Please choose a seat.
  </p><br />

<?php

/* connect to data base */
require ('./secure/connect.php');



echo "<table>\n<tr>\n";
$no = 1;
$query = "SELECT * from seats_table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
    $status = ($row['taken']) ? "Taken by $row[user_id]" : '<a href="reserve_seat.php?seat='.$no.'">Available</a>'; 
    echo "<td>Seat $no<br/>$status</td>\n";
    $no++;
echo "</tr>\n<\table>\n";

?>



  	 <br />
<hr /><br />

<?php	
$result = mysql_query("SELECT user_level FROM users WHERE username='".$_SESSION['username']."'")or die(mysql_error());
$row = mysql_fetch_array($result);

if ($row['user_level'] ==1) 
{ 
	echo '<a href="./admin/admin-panel.php">Admin Panel</a> -';
} 
?>
<a href="signup.php">Events Signup</a>
-
<a href="password.php">Change Password</a>
-
<a href="editprofile.php">Edit Profile</a>
-
<a href="logout.php">Logout</a>
  

<div class="clear"> </div>
    </div>
    
    <div class="clear"> </div>
  
  <!-- End content Columns -->
  <!-- Begin Footer -->
  <div id="footer">Lee Brenchley - University of Plymouth © 2011 </div>
  <!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>

 

i tried the page without the code that you just gave me and it displays fine so there must be something missing from there

 

thanks,

 

Lee

Link to comment
Share on other sites

ah i saw you missed a } so i have added that in and had a play around with the code and its working fine. i knew there had to be a more efficient way of doing it opposed to having the same code 49 times but just incrementing the seat number and array etc, thank you very much  :D

 

 

Link to comment
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.