duan051347 2012-07-12 12:13
浏览 45
已采纳

查看MySql的PHP IF语句

Sorry, I should have put more information in the question

I am trying to figure out how to create a if statement that looks at a mysql field for example: if date ("D") = mysqlDateField

I have a small site that users put reminders into a forum to be sent to a specified email address on days they setup.

The days are stored in a mysql database in mon, tue, wed, etc. format.

The users can select multiple days so I have a field for each day (not sure if that is the best way to do it or not)

so I have a sendmail script that runs and sends out the emails with the reminders the users specified.

I want the if statement to check the current day against the day in the database

I am using the date ("D") format currently since it matched what wa stored in the database

After looking around the different forums and w3schools I came up with this below but it is not working, I am new to php and mysql and not exactly sure how to get it working the way I want

$result = mysql_query("SELECT * FROM users")or die(mysql_error());
$d = date ("D");

if (mysql_num_rows($result)==$d)

Thanks

  • 写回答

1条回答 默认 最新

  • dongzi9196 2012-07-12 12:20
    关注

    Some little note before the code sample:

    • creating a date to compare with D is bad, use some more useful format like 'Ymd';
    • the date you're going to compare must be in the same format (you should not compare a ymd with a ymdhis date) becouse else they will give you inconsistent result. Convert or format the date before using them.
    • you are receiving a lot of result via wildcard query on tables, you should avoid when possible a SELECT *

      foreach($result as $row){    
          if(strtotime($row['field_with_date']) == strtotime($d)){ } }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?