dtwkt46424 2013-03-13 11:55
浏览 437
已采纳

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

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.

  • 写回答

4条回答 默认 最新

  • dongzan7016 2013-03-13 11:58
    关注

    Assuming that status=0 if the free seat:

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

    Full example, from php manual:

    <?php
      $link = mysqli_connect("localhost", "my_user", "my_password", "world");
    
      /* check connection */
      if (mysqli_connect_errno()) {
          printf("Connect failed: %s
    ", 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);
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘