Web Analytics Made Easy -
StatCounter Generating a table with variables - CodingForum

Announcement

Collapse
No announcement yet.

Generating a table with variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating a table with variables

    Here is the code I have written so far.

    <form action="oneroomtable.php" method="post">

    Choose which <b>room</b> you would like to check availability for: &nbsp

    <select name="room">
    <option value=>---- Select One ----</option>

    <?php
    $conn = mysql_connect();
    mysql_select_db("test", $conn);
    $sql = "SELECT roomnum FROM room";
    $result = mysql_query($sql, $conn) or die(mysql_error());

    while ($newArray = mysql_fetch_array($result))
    {
    $rooms = $newArray[roomnum];



    for ($x=1; $x <= count($rooms); $x++) {
    print "\t<option value=\"$rooms\"";
    print ($x == $rooms)?" SELECTED":"";
    print ">"."\n";
    }

    echo "$rooms <br>";

    }
    ?>

    </select>
    <br><br><br>

    Select the <b>date</b> and <b>time</b> you would like the booking for.
    Then search for room availability:
    <br><br>
    <?php

    include("date_pulldown.class.php");

    $date1 = new date_pulldown("fromdate");
    $date2 = new date_pulldown("todate");

    ?>


    <p>
    <strong>Date From:</strong>
    <?php print $date1->output(); ?>
    <br><br>
    <p>
    <strong>Date To:&nbsp&nbsp&nbsp&nbsp</strong>
    <?php print $date2->output(); ?>

    <p>
    <strong>Time From:&nbsp&nbsp</strong>
    <select name="ftime">
    <option value="8:00">8:00
    <option value="9:00">9:00
    <option value="10:00">10:00
    <option value="11:00">11:00
    <option value="12:00">12:00
    <option value="13:00">13:00
    <option value="14:00">14:00
    <option value="15:00">15:00
    <option value="16:00">16:00
    <option value="17:00">17:00
    <option value="18:00">18:00
    <option value="19:00">19:00
    </select>

    <br><br>

    <p>
    <strong>Time To:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</strong>
    <select name="ttime">
    <option value="8:00">8:00
    <option value="9:00">9:00
    <option value="10:00">10:00
    <option value="11:00">11:00
    <option value="12:00">12:00
    <option value="13:00">13:00
    <option value="14:00">14:00
    <option value="15:00">15:00
    <option value="16:00">16:00
    <option value="17:00">17:00
    <option value="18:00">18:00
    <option value="19:00">19:00
    <option value="20:00">20:00
    </select>

    <br><br><br>



    <center>
    <p><input type="submit" name="submit" value="Search Availability"></p>
    </center>


    I want to be able to generate a table
    with the headings of columns as times

    eg.

    -----------------------------
    | |9:00|10:00|11:00|12:00|
    ----------------------------|
    | | |
    | | |
    | | |
    -----------------------------

    But I don't know how to convert the string that I get from $_post
    into an integer so that I can loop from start time to the end time.

    Can anyone help please?

  • #2
    Couple of things seetz10,

    when posting php code, put [ php ] ... [/ php ] tags (no spaces) around the code so that it turns on the syntax highlighting. makes it easier to read...

    regarding your question, I'd like to get some more specifics:
    this table you'd like to generate, I'm not sure I understand what's meant to go in it. For example, do you want existing bookings to appear or the user's booking, or what?

    Also, what do you mean exactly by
    But I don't know how to convert the string that I get from $_post
    into an integer so that I can loop from start time to the end time.
    Like what string do you get from $_post? Do you mean the start time and end time are stored as strings? because in that case you can just type cast it. For example,
    PHP Code:
     $string_version "34";
     
    $int_version = (int)$string_version
    In your case, you've also got the :00 to take into account. Before you convet the string to an integer, I would do something like the following:
    PHP Code:
     $ftime = (int) (substr($ftime0, -3)); 
    This will delete the last 3 characters from the string.

    Hope that helps, if you have any further problems, please post.
    Sadiq.

    Comment


    • #3
      Thanks for your help.

      The type casting worked!

      In the table I wanted to show rooms that have booked. Eg. The cell will contain the letter B. But the remaining cells, I want the cells to be check boxes. Do you know if it is possible for a table to consist of cells with checkboxes?

      seetz

      Comment


      • #4
        seetz10,

        It is indeed possible for a table to consist of cells containing checkboxes, but there are a few things you should take into account:

        You'll have to name these checkboxes carefully to ensure that you can retrieve their values in a nice way in PHP.

        Also, regarding checkboxes, if they are NOT checked, their values will NOT be passed over to the server on submit. So if you cannot find values in your $_POST array or something, it's most probably because those checkboxes have not been checked.

        Some weird error checking may come into play. For example, what if your users (and I'm not exactly sure how you're planning on setting this up, but) check off boxes that don't correspond with eachother? There can be some weird occurences, so be wary.

        Anyway, hope that helps.
        Sadiq.

        Comment

        Working...
        X