dongzhiman2162 2013-02-18 15:15
浏览 70

在PHP中使用数据库信息作为常量

I don't exactly know how to word this, so I am going to try my best at it. I am trying to make a constant out of a certain column within my database. What is it is a site where you can make reservations to certain events being held. Within the database there is a column for the maximum number of seats(num_seats) at the specific venue. On the website, it shows the max number of seat left/available(number subtracts when someone reserves a seat(s)). What I am trying to do, is at a certain number have the availability go from Available to Limited to None. The "None" part is easy, what I am looking for is the Limited. I want it to change to "Limited" when only about 1/3 of the venue is available.

Now, when the owner enters the number of seats(we'll say 100), the database populates with 100, so 1/3 would be roughly 34. My problem is, when a person register, the number goes down, so 99 = 33, 90 = 31, 80 = 26. It will always change, so if I say:

if($num_seats < $row['num_seats'] / .33) {
    echo "Limited";
}

This will never be true since it always changes. My question(sorry for being "long-winded") is, is there of making the number a constant within my php code, or will it just be easier to add a new column to the database and have one named max_num_seats and the other name seats_avail?

Thanks in advanced...

  • 写回答

1条回答 默认 最新

  • dongqing7789 2013-02-18 15:28
    关注

    Use two tables: one for the 'owner' where the total number of seats is stored and another for the reservations. Then do your join/select and figure out what to display.

    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)