简体   繁体   English

PHP + MYSQL座位预约系统。 计算免费座位

[英]PHP + MYSQL Seating Reservation System. Counting free seats

I have a table like this: 我有这样一张桌子:

    $sql = "CREATE TABLE dramaStudio
   (
   rowId varchar(1) not null,
   columnId int not null,
   status int,
   firstName varchar(15) not null,
   lastName varchar(15) not null,
   updatedby varchar(10),
   PRIMARY KEY (rowId, columnId)
   )";

On the homepage of my website I would like the user to be able to see if there are any free seats without going on to the seating plan. 在我的网站的主页上,我希望用户能够看到是否有任何免费座位而无需进入座位计划。 Pretty much just a bit saying 'free seats:'followed by a number. 几乎只是说“免费席位:”后跟一个数字。 My logic in pseudo code would be: 我在伪代码中的逻辑是:

$j=0 
select * from dramaStudio
for every status == 0
    $j+1
echo $j

Any help will be greatly appreciated. 任何帮助将不胜感激。

只需对状态为0的所有字段执行COUNT操作?

SELECT COUNT(*) FROM dramaStudio WHERE status = '0'

Assuming that status=0 if the free seat: 假设空闲席位的状态= 0:

SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0

Full example, from php manual: 完整的例子,来自php手册:

<?php
  $link = mysqli_connect("localhost", "my_user", "my_password", "world");

  /* check connection */
  if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }

  $query = "SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0";
  $result = mysqli_query($link, $query);

  /* associative array */
  $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  echo $row['freeseats']; // this is an integer

  /* free result set */
  mysqli_free_result($result);

  /* close connection */
  mysqli_close($link);
?> 

See sample code 请参阅示例代码

$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("test_db",$con);

$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);

while ($property = mysql_fetch_field($result))
  {
  echo "Field name: " . $property->name . "<br />";
  echo "Table name: " . $property->table . "<br />";
  echo "Default value: " . $property->def . "<br />";
  echo "Max length: " . $property->max_length . "<br />";
  echo "Not NULL: " . $property->not_null . "<br />";
  echo "Primary Key: " . $property->primary_key . "<br />";
  echo "Unique Key: " . $property->unique_key . "<br />";
  echo "Mutliple Key: " . $property->multiple_key . "<br />";
  echo "Numeric Field: " . $property->numeric . "<br />";
  echo "BLOB: " . $property->blob . "<br />";
  echo "Field Type: " . $property->type . "<br />";
  echo "Unsigned: " . $property->unsigned . "<br />";
  echo "Zero-filled: " . $property->zerofill . "<br /><br />";
  }

mysql_close($con);

you are storing the filled seat? 你正在存放填充的座位? to find out empty you have to specify number of colomn and rows. 找出空的你必须指定colomn和行的数量。

and if the filled and empty seat is distinguishable on status in table. 如果填充和空座位在表格中可以区分。 you can do like this, 你可以这样做,

    $query = "select * from dramaStudio where status = 0";
    $result_Set = mysql_query($query);
    while($row = mysql_fetch_object($result_set)){
        echo $row->rowId .',', $row->columnId; 
        echo '</br>';
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM