1 Reply Latest reply: Sep 13, 2014 3:53 PM by Rob Hecker2 RSS

    Simple booking system

    Max Resnikoff Community Member

      Hi,

       

      I have a database with books in it, and I was wondering if there is a way in which I can mark the book either Booked out or in store.

       

      Maybe something simple like : if field = 1 (then its booked) if field = 2(then it is in store). and they would display a different icon depending if the field is 1 OR 2?

       

      I dont want to make it too complicated. Just something nice and simple.

       

      Any help would be very much appreciated.

        • 1. Re: Simple booking system
          Rob Hecker2 CommunityMVP

          Yes, that is how it is often done. Create a column in your table of the integer type and call it status, or something like that.

           

          Then there are several ways to process the result of status with PHP. Firstly:

          if ($status == 1){

          // do something

          } elseif ($status == 2){

          //do sometihng else

          } else {

          //default behavior

          }

           

          If you have many options for status, then it is often useful to use the "switch" method. Just google somethhing like PHP switch flow control."

           

          If there are just two options, you can use the ternary operator, like this:

          $result = ($status == 1)? "this is the result" : "this is what's returned if it isn't 1";

           

          Note that in your examples you use a single equal sign but it should be a double. A double equal tests for equality but a single creates equality.