SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    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
    717
    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
    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

  5. #5
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    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

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

  7. #7
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    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

  8. #8
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    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

  9. #9
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Table name bookedseat

    Rows
    id autoinc
    busnumber
    seatnumber
    ------------------------------------------------------------------------
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  10. #10
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    It's a little hard to follow with the JS in there as to the intent of onclick action especially when all parts of the page are unknown. Noticed also you lost the "Bus" grid you desired in OP. I'll take a shot in the dark with this example.

    PHP Code:
    <?php
    //Query for booked seats
    $k = array();
    $setnumber =mysql_query("SELECT seatnumber FROM bookedseat where busnumber='".$b_id."'");
        while(
    $rowmysql_fetch_array($setnumber))
        {
            
    $k[] = $row['seatnumber'];
        }
    $ais = array("A","B","E","C","D");
    $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++){
            
    $seatno $i.$r;
            if(
    in_array($seatno,$k)){
                
    $seat '<input type="checkbox" disabled="disabled" value="'.$seatno.'" class="box'.$b_id.'" name="seat[]" style="width:18px; height:18px;" id="'.$fare.'" onclick="getSum();" >';
            }elseif(!
    in_array($seatno,$aisle)){
                
    $seat '<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);" >';
            }else{
                
    $seat "&nbsp;";
            }
            echo 
    "<td>$seat</td>\r";
        }
        echo 
    "</tr>\r";
    }
    echo 
    "</table>\r"

    ?>

  11. #11
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much.

    It's working Correctly

    Thanks a lot.
    ------------------------------------------------------------------------
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  12. #12
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Now that you have that working, I would HIGHLY recommend you switch over to PDO query. It's not that much different.

    Connection:
    PHP Code:
    <?php
    $host 
    "localhost"
    //Database user name.    
    $login "";
    //Database Password.
    $dbpass "";
    //Database name.
    $dbname "";
    $PDO = new PDO("mysql:host=localhost;dbname=$dbname""$login""$dbpass");
    ?>
    And the Query:
    PHP Code:
    <?php
        
    //Query for booked seats
        
    $k = array();
        
    $sql "SELECT seatnumber FROM bookedseat where busnumber = :busnumber"
        
    $query $PDO->prepare($sql);  
        
    $query->bindParam(":busnumber"$b_id); 
        
    $query->execute();  
        while(
    $row $query->fetch(PDO::FETCH_ASSOC)){
            
    $k[] = $row['seatnumber'];
        }
    ?>

  13. #13
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    it's important and if the answer is yes for your site so please me why is it important.
    ------------------------------------------------------------------------
    Best Regards,
    Kewal Knojiya
    Kewal | Kanojia | Kewal Kanojia | PHP Web Developer

  14. #14
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. This means at some point your host may upgrade their server and mysql may not be supported.
    Also using bindParam() as in my example, you are escaping values e.g. joe\'s and protecting against SQL injection attacks where someone might try to submit malicious code into a form field to gain access to your database.

  15. #15
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Also see this post.

  16. #16
    SitePoint Enthusiast knojiyak's Avatar
    Join Date
    Oct 2013
    Posts
    66
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello Sir,

    I want my Bus name link image which is given below i hope you will help me as soon as possible.

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

  17. #17
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    717
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Hey, I know this thread is a little old but I never got back to you. Tables are built in rows and you are asking for seats to be numbered by column. That's a little hard to pull off, especially when dealing with aisle spaces, where you would skip a number. I ended up making an array using the existing letter/number combination as the key and the value being the number you wish to see. Using seat images as the cell background and the link/number as the value.
    PHP Code:
    <!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></title>
    <style type="text/css">
    .oc {
    margin:0;
    padding:0;
    background-image:url('images/seatoccupied.png'); 
    width:33px; 
    height:26px; 
    border:none; 
    text-align:center;
    line-height:26px; 
    font-family:Helvetica;
    font-size:16px;
    font-weight:bold;
    }
    .oc a, a:link, a:hover {
    color: black;
    text-decoration: none;
    }
    .emp {
    margin:0;
    padding:0;
    background-image:url('images/seatempty.png'); 
    width:33px; 
    height:26px; 
    border:none; 
    text-align:center;
    line-height:26px; 
    font-family:Helvetica;
    font-size:16px;
    font-weight:bold;
    color: black;
    text-decoration: none;
    }
    .emp a, a:link, a:hover{
    color: black;
    text-decoration: none;
    }
    .non { 
    margin:0;
    padding:0;
    width:33px; 
    height:26px; 
    border:none; 
    text-align:center;
    color: white;
    text-decoration: none;
    }
    </style>
    </head> 
    <body>
    <?php
        
    //Query for booked seats
        
    $k = array();
        
    $sql ="SELECT seatnumber FROM bookedseat where busnumber = :busnumber"
        
    $query $PDO->prepare($sql);  
        
    $query->bindParam(":busnumber"$b_id); 
        
    $query->execute();  
        while(
    $row $query->fetch(PDO::FETCH_ASSOC)){
            
    $k[] = $row['seatnumber'];
        }
    ?>
    <?php
    $ais 
    = array("A","B","E","C","D");
    $aisle = array("E1","E2","E3","E4","E5","E6","E7","E8","E9");
    $seatnumbers = array(
    "A1" => "1","A2" => "5","A3" => "9","A4" => "13","A5" => "17","A6" => "21","A7" => "25","A8" => "29","A9" => "33","A10" => "37",
    "B1" => "2","B2" => "6","B3" => "10","B4" => "14","B5" => "18","B6" => "22","B7" => "26","B8" => "30","B9" => "34","B10" => "38",
    "E1" => "&nbsp;","E2" => "&nbsp;","E3" => "&nbsp;","E4" => "&nbsp;","E5" => "&nbsp;","E6" => "&nbsp;","E7" => "&nbsp;","E8" => "&nbsp;","E9" => "&nbsp;","E10" => "39",
    "C1" => "3","C2" => "7","C3" => "11","C4" => "15","C5" => "19","C6" => "23","C7" => "27","C8" => "31","C9" => "35","C10" => "40",
    "D1" => "4","D2" => "8","D3" => "12","D4" => "16","D5" => "20","D6" => "24","D7" => "28","D8" => "32","D9" => "36","D10" => "41");

    echo 
    "<table border=0 cellpadding=0 cellspacing=0>\r";
    foreach(
    $ais as $i){
        echo 
    "<tr>\r";
        for(
    $r=1;$r<=10;$r++){
            
    $seat $i.$r;
            
    $setnum $seatnumbers[$seat];
            if(
    in_array($seat,$k)){
                
    $bg " class=\"oc\"";
            }elseif(!
    in_array($seat,$aisle)){
                
    $bg " class=\"emp\"";
            }else{
                
    $bg " class=\"non\"";
            }
            if(
    is_numeric($setnum)){
                echo 
    "<td" $bg "><a href=?seatnum=" $setnum ">" $setnum "</a></td>\r";
            }else{
                echo 
    "<td" $bg ">" $setnum "</td>\r";
            }
        }
        echo 
    "</tr>\r";
    }
    echo 
    "</table>\r"
    ?>
    </body>
    </html>
    Looks like this
    Sample228.jpg


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
  •