SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Hybrid View

  1. #1
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    73
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    How can i make a bus seat layout in PHP?

    Hello Friends,

    There is new problem with me I hope you will give me a perfect solution of this Problem.

    I want to make a bus seats layout using php How can i make it? Please help me.

    There is a image which is the layout of the bus seats.

    bus.png
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  2. #2
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    As usual, I'm sure someone will post a better version but here goes anyway.
    PHP Code:
    <?php 
    //Seats booked for this sample
    $seats = array("B8","C7","A1","B1");

    //The aisles.  Note E is walkway and single seat in back
    $ais = array("A","B","E","C","D");

    //Walkway or aisle seats
    $aisle = array("E1","E2","E3","E4","E5","E6","E7","E8","E9");

    echo 
    "<table>\r";
    foreach(
    $ais as $i){
        echo 
    "<tr>\r";
        for(
    $r=1;$r<=10;$r++){
            
    $seat $i.$r;
            if(
    in_array($seat,$seats)){
                
    $image "<img src=\"images/seatoccupied.png\" border=\"0\" width=\"33\" height=\"26\" alt=\"\" />";
            }elseif(!
    in_array($seat,$aisle)){
                
    $image "<img src=\"images/seatempty.png\" border=\"0\" width=\"33\" height=\"26\" alt=\"\" />";
            }else{
                
    $image "&nbsp;";
            }
            echo 
    "<td>$image</td>\r";
        }
        echo 
    "</tr>\r";
    }
    echo 
    "</table>\r";
    ?>
    seatempty.pngseatoccupied.png

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please refer following link w3schools.invisionzone.com/index.php?showtopic=21295

  4. #4
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    73
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your code but i have one important problem. The problem is that i want to disable booked seat it will fetch from database so please provide me that code also.
    I am so confused please help me.

    Untitled-1.png

    Thank you in advance.
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  5. #5
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    If you provide current code you are using maybe we can help.

  6. #6
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    73
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That is the current which i am using.

    <?

    $ais = array("A","B","E","C","D");
    $aisle = array("E1","E2","E3","E4","E5","E6","E7","E8","E9");
    foreach($ais as $i){
    $setnumber =mysql_query("SELECT * FROM test where busid='".$b_id."'");
    while($row= mysql_fetch_array($setnumber))
    {
    $k = array($row['1']);
    }
    for ($x=1; $x<=10; $x++)
    {
    $seatno = $i.$x;
    if(in_array($seatno,$aisle))
    {
    echo '<input type="checkbox" disabled="disabled" value="'.$seatno.'" class="box'.$b_id.'" name="seat[]" style="width:18px; height:18px;" id="'.$fare.'" onclick="getSum();" >';
    }
    else if($seatno == $k)
    {
    echo '<input type="checkbox" disabled="disabled" value="'.$seatno.'" class="box'.$b_id.'" name="seat[]" style="width:18px; height:18px; outline : 1px solid #ff0000; cursor:url(images/pen.png),auto; " id="'.$fare.'" onclick="getvalue'.$b_id.'();test'.$b_id.'(this);" >';
    }
    else{
    echo '<input type="checkbox" value="'.$seatno.'" name="seat[]"
    style="width:18px; height:18px; cursor:url(images/pen.png),auto; outline : 1px solid #009900;" class="box'.$b_id.'" id="'.$fare.'" onclick="getvalue'.$b_id.'();test'.$b_id.'(this);" >';
    }
    }

    }

    ?>
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  7. #7
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    What are your table fields and how are you defining a seat that is booked? Avoid using * when making a query. Instead use the table fields that are needed, e.g. id,seatnum,busid

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2014
    Posts
    41
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I would just like to point out that you don’t need any PHP to create any particular design unless you want it to be data driven


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •