Seating Reservation System - PHP + MYSQL

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

82 Replies - 13618 Views - Last Post: 23 March 2013 - 09:19 AM Rate Topic: -----

#31 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 06:57 AM

View PostDormilich, on 06 March 2013 - 06:49 AM, said:

correct, itís the quotes. field names are not quoted by apostrophes (only by backticks), so if you write firstName = A SQL reads "assign the value of field A to field firstName". then why does it work with numbers? because numbers cannot be field names.

So I guess I need to declare it a variable? or make it recognize its a vchar? How would i go about that?

Quote

PS. another matter that doesnít exist with prepared statements.

As i fix mine I'm trying to get your PDO example to work. However no luck yet, you mention initializing it ?

wow I'm actually learning :D ! Thank you so much !
Was This Post Helpful? 0
  • +
  • -

#32 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 07:12 AM

oh just added the ' ' round and it works, thank you !!

This post has been edited by carmex: 06 March 2013 - 07:17 AM

Was This Post Helpful? 0
  • +
  • -

#33 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 08:02 AM

View Postcarmex, on 06 March 2013 - 02:57 PM, said:

As i fix mine I'm trying to get your PDO example to work. However no luck yet, you mention initializing it ?

you neet a connection to the database. without that, even PDO "does not work". there are some PDO tutorial in the tutorialsí section where you can see that.


View Postcarmex, on 06 March 2013 - 02:57 PM, said:

wow I'm actually learning :D/> !

that is why I donít hand out the ready code.
Was This Post Helpful? 0
  • +
  • -

#34 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 08:26 AM

What are the advantages over pdo over the way I'm doing it.
Field name collision is obviously one, what are others.. Efficiency?

Once again massive thank you.
One massive thing I'm going to take away is always, always, always use an error report :P
Was This Post Helpful? 0
  • +
  • -

#35 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 06 March 2013 - 08:31 AM

other advantages
- no worries about SQL Injection
- multiple output types (i.e. you can fetch data into a class)
- repetition (if you have multiple data sets (seats), you only need to prepare once and then you only submit each of the data (each seat))
- PDO can use exceptions for error handling
- you can loop over a PDOStatement directly
- PDO supports Transactions
Was This Post Helpful? 1
  • +
  • -

#36 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 04:40 AM

Hi Dormilich,
Need some further advice on another idea.
Basically:
On the home page i would like it to show the available seats in each venue without having to access the seating plan page.
I just need some help on the writing of this code.
My logic in Pseudo code is:
j=0
Select * from school hall 
  for every status == 0:
    j+1

echo j


How would i go about doing this in php?
Thanks in advance

This post has been edited by carmex: 13 March 2013 - 04:40 AM

Was This Post Helpful? 0
  • +
  • -

#37 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:37 AM

if you just want the amount of available seats, use SQLís COUNT() function.
SELECT COUNT(*) FROM seat_table WHERE status = 0;
Was This Post Helpful? 2
  • +
  • -

#38 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:38 AM

View PostDormilich, on 13 March 2013 - 05:37 AM, said:

if you just want the amount of available seats, use SQLís COUNT() function.
SELECT COUNT(*) FROM seat_table WHERE status = 0;


I've tried that, cannot get it to echo or display its results :/
Was This Post Helpful? 0
  • +
  • -

#39 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:40 AM

then, how did you try to echo the result (MySQL doesnít do that automatically)?
Was This Post Helpful? 0
  • +
  • -

#40 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:44 AM

View PostDormilich, on 13 March 2013 - 05:40 AM, said:

then, how did you try to echo the result (MySQL doesn’t do that automatically)?



$sql = "SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0";
mysql_query($sql);
echo $sql;

$sql = "SELECT COUNT(*) AS $freeseats FROM dramaStudio WHERE status=0";
echo $freeseats;

$query = "SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0";
$result = mysql_query($query);
echo $result;






a few ways ://>

This post has been edited by carmex: 13 March 2013 - 05:47 AM

Was This Post Helpful? 0
  • +
  • -

#41 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:51 AM

nothing of that is even close.

thatís simply not how you get DB data at all. DB data need to be fetched.
Was This Post Helpful? 0
  • +
  • -

#42 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:56 AM

View PostDormilich, on 13 March 2013 - 05:51 AM, said:

nothing of that is even close.

that’s simply not how you get DB data at all. DB data need to be fetched.



$result = mysql_query("SELECT COUNT(*) AS freeseats FROM schoolHall WHERE status=0");
$row = mysql_fetch_array($result);
echo $row[0];


? how about this?

This post has been edited by Dormilich: 13 March 2013 - 05:57 AM
Reason for edit:: please use [code] [/code] tags when posting code

Was This Post Helpful? 0
  • +
  • -

#43 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:57 AM

does it do what you want?
Was This Post Helpful? 1
  • +
  • -

#44 carmex  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 21-February 13

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:59 AM

View PostDormilich, on 13 March 2013 - 05:57 AM, said:

does it do what you want?


YES! :D thank you!

I'm also trying to implement a search function for the user to search whether someone has made a booking. Do you know any tutorials for this that will help?
Was This Post Helpful? 0
  • +
  • -

#45 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,609
  • Joined: 08-June 10

Re: Seating Reservation System - PHP + MYSQL

Posted 13 March 2013 - 05:59 AM

the reason PDO does not always call its fetch() method is that in a foreach loop the fetch() method is called automatically.
Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »