updated final php code 7.3 KB
Newer Older
G.K.V.S.S.R.PAVAN's avatar
G.K.V.S.S.R.PAVAN committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
<?php
echo "<body style='background-color:white'>";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "projectbus1";

$conn = mysqli_connect("localhost","root","","projectbus1");
// Check connection
if ($conn->connect_error) {
    
    die("Connection failed: " . $conn->connect_error);
} 
if ((isset($_POST['submit'])))
{     echo"<br>";echo"<br>";echo"<br>";echo"<br>";echo"<br>";echo"<br>";
        echo "<p align=center>WELCOME TO KL_RTC</p>"; 
        //echo "<br>";
        $presentlocation = $_POST['presentlocation'];
  $destination = $_POST['destination'];
  if($presentlocation==1)
    {echo "<p align=center>Present location-VIJAYAWADA </p>";}
  elseif($presentlocation==2) 
  {echo "<p align=center>Present location-TADEPALLI </p>";}
  elseif($presentlocation==3)
  {echo "<p align=center>Present location-PATHURRU</p>";}
  elseif($presentlocation==4)
  {echo "<p align=center>Present location-MANGALAGIRI</p>";}
  elseif($presentlocation==5)
  {echo "<p align=center>Present location-GUNTUR</p>";}

    //echo " To ";

  if($destination==1)
  {echo "<p align=center>Destination-VIJAYAWADA</p>";}
elseif($destination==2) 
{echo "<p align=center>Destination-TADEPALLI</p>";}
elseif($destination==3)
{echo "<p align=center>Destination-PATHURRU</p>";}
elseif($destination==4)
{echo "<p align=center>Destination-MANGALAGIRI</p>";}
elseif($destination==5)
{echo "<p align=center>Destination-GUNTUR</p>";}   
  //echo "<br>";

  $sqlwselect = "SELECT * FROM `destination` WHERE `destination`.`destination` <= $presentlocation ";
  $resultselect= mysqli_query($conn,$sqlwselect);
  while($roww = mysqli_fetch_array($resultselect))
  {
    $seatselect= $roww['seatnum'];
    //echo " seattt.....$seatselect";
    $sqlselect = "INSERT INTO assignseat(Seatnum) VALUES('$seatselect')";
    $resultinsert=mysqli_query($conn,$sqlselect);
  }
$sqlw = "DELETE FROM `destination` WHERE `destination`.`destination` <= $presentlocation ";
$resu=mysqli_query($conn,$sqlw);
$sqlwdeleting = "DELETE FROM `deleting` WHERE `deleting`.`destination` <= $presentlocation ";
$resu=mysqli_query($conn,$sqlwdeleting);

$count="SELECT * FROM destination";
$resulttt=mysqli_query($conn,$count);
$num_row=mysqli_num_rows($resulttt);
 //for deletetable....
 $countdelete="SELECT * FROM deleting";
 $resultdeleting=mysqli_query($conn,$countdelete);
  $num_row_delete=mysqli_num_rows($resultdeleting); 
  $num_rows=$num_row+$num_row_delete+1;   
 echo "<p align=center>Total no of passengers-$num_rows</p>"; 
 //echo "Total no of passengers-$num_rows \n";
 //echo "<br>";
 if($num_rows<"40")
 {
 echo "<p align=center>seats are available</p>"; 
 //{echo "seats are available";
 //echo "<br>";
}
 else
 {
 echo "<p align=center>seats are not available</p>"; 
 //{echo "seats are not available";
 //echo "<br>";
}
 
 $sqlww = "SELECT MAX(seatnum) as max_seatnum FROM destination";
 $resultt=mysqli_query($conn,$sqlww);
 if (!$resultt) {
  printf("Error: %s\n", mysqli_error($conn));
  exit();
}
	$row=mysqli_fetch_array($resultt);
//$seatno=$row['S.No'];
//$destination=$row['destination'];
//printf("%d\n",$row[0]"."<br>";
//echo "pav";
$seat=$row['max_seatnum'];




$seat=$seat+1;



if($num_rows<"40")

{
  $countt="SELECT * FROM assignseat";
  $resultttt=mysqli_query($conn,$countt);
  //echo "value2-$resulttt";
  $num_roww=mysqli_num_rows($resultttt);
  $num_rowsinassign=$num_roww; 
  //echo "noofemptyseats=$num_rowsinassign";   
 if($num_rowsinassign > "0")
 {
  $sqlassign="SELECT MIN(Seatnum) as min_seatnum FROM assignseat";
  $resultassign=mysqli_query($conn,$sqlassign);
  if (!$resultassign) {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
  $rowassign=mysqli_fetch_array($resultassign);
  $seat=$rowassign['min_seatnum'];
  echo "<p align=center>Seatnum-$seat</p>";
  $sqlassigndelete="DELETE FROM `assignseat` WHERE Seatnum IN (select min(Seatnum) from `assignseat`)";
  $resultassigndelete=mysqli_query($conn,$sqlassigndelete);
 }
 else
 {
   echo "<p align=center>seatnum-$seat</p>";
 }
 // echo "need to add more code";
  /**for($abc=1;$abc<=40;$abc++)
  {
  $sqlquery="SELECT  * FROM destination where 'destination'.'seatnum'=$abc";
  $sqlresult=mysqli_query($conn,$sqlquery);
 // $roww=mysqli_fetch_array($sqlresult);
  //$seatfor=$roww['seatnum'];
  echo "forloop-$sqlresult";
  echo "<br>";

  if(!$sqlresult) 
  {
    echo "seatnuminside-$abc";
    $seat=$abc;
    printf("Error: %s\n", mysqli_error($conn));
    //exit();
    break;
  }*/
 // }
  //echo "<br>";
}
else if($num_rows>="40")
{
  //$sqlelseif="SELECT * FROM destination WHERE destination < '$destination' ";
  $sqlelseif="SELECT * FROM destination WHERE destination < '$destination' ";
  $resultif=mysqli_query($conn,$sqlelseif);
  while($rowgreater=mysqli_fetch_array($resultif))
  {
    $greaterdestination=$rowgreater['destination'];
    $greater="INSERT INTO greater('destination') values ('$greaterdestination')";
    $sqlgreatercon=mysqli_query($conn,$greater);
  }
  $greaterrows=mysqli_num_rows($resultif);
  //echo "....$greaterrows.....";
  if (!$resultif) 
  {
    echo "no lesser destination available";
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
  if($greaterrows== 0)
  {
    $seat=0;
   // echo "no lesser destination available";
  }
  else
  {
  $resultif=mysqli_query($conn,$sqlelseif);
  while($row  = mysqli_fetch_array($resultif))

  {
   // echo "helloo";
    $presentatdestination = $row['present'];
    $destinationatdestination = $row['destination'];
    $seatatdestination = $row['seatnum'];
  }
 // echo "presentvaluees-$presentatdestination";
  //echo "destinationvalues-$destinationatdestination";
  //echo "seatvaluees-$seatatdestination";
  $sql = "INSERT INTO deleting (present,destination,seatnum) VALUES('$presentatdestination','$destinationatdestination','$seatatdestination')";
  $result=mysqli_query($conn,$sql);
  if (!$result) 
  {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
  
  $sqlwgreater = "DELETE FROM `destination` WHERE `destination`.`seatnum` = $seatatdestination ";
  $resu=mysqli_query($conn,$sqlwgreater);
  echo "<p align=center>seat-$seatatdestination at destination-$destinationatdestination</p>";
  echo "<br>";
  $seat=$seatatdestination;
  }
}  
  



/*  echo "testing-$resultif";
  if (!$resultif) {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
  $rowif=mysqli_fetch_array($resultif);
  $seat=$rowif['seatnum'];
  $comingplace=$rowif['destination'];
  echo "seatnumelseif-$seat"."at-$comingplace";
  echo "<br>";
}
else
{
  echo "seatnum=$seat";
  echo "<br>";
}*/

$sql = "INSERT INTO destination (present,destination,seatnum) VALUES('$presentlocation','$destination','$seat')";
  $result=mysqli_query($conn,$sql);
  if (!$result) {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
  $sql = "INSERT INTO temp (present,destination,seatnum) VALUES('$presentlocation','$destination','$seat')";
  $result=mysqli_query($conn,$sql);
  if (!$result) 
  {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
  }
echo "<p align=center>THANKS FOR USING KL_RTC</p>";
  //echo "value2-$result"."<br>";
  //$x++;
     
      
 	


      // $Seatnum=110178;
        //$sql = "INSERT INTO seatnumt (Seatnum) VALUES('$Seatnum')";
        //$result=mysqli_query($conn,$sql);
        //echo "hlooo";
}

/*if ($conn->query($sql) === TRUE) {
  header('Location: retrive.php');
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;

}*/
?>