PHP foreach,if语句(PHP foreach, if statement)
我有一个表格列出了几个元素及其到期日期。
我需要一个函数,说“如果到期日期晚于今天(对于每个元素),那么就不要显示”。
看起来很简单,但我卡住了!
编辑
<?php foreach($codes->result_array() as $row):?> <tr> <td><?php print $row['description']?></td> <td><?php print $row['credits']?></td> <td><?php print $row['code']?></td> <td><? echo date("F jS, Y", strtotime($row['exp_date']));?></td> <td><? echo date("F jS, Y", strtotime($row['create_date']));?></td> <td> <!-- Icons --> <a href="<? echo base_url()?>admin/home/editCode/<?php print $row['id']?>" title="Edit"><img src="<? echo base_url()?>assets/images/icons/pencil.png" alt="Edit" /></a> <a href="<? echo base_url()?>admin/home/deleteCode/<?php print $row['id']?>" title="Delete" class="delete-code"><img src="<? echo base_url()?>assets/images/icons/cross.png" alt="Delete" /></a> </td> <?php endforeach;?>
I have a table listing several elements, and their expiration date.
I need a function that says, "If the expiration date is later than today (for each element), then don't show".
It seems pretty simple, but I'm stuck!
Edit
<?php foreach($codes->result_array() as $row):?> <tr> <td><?php print $row['description']?></td> <td><?php print $row['credits']?></td> <td><?php print $row['code']?></td> <td><? echo date("F jS, Y", strtotime($row['exp_date']));?></td> <td><? echo date("F jS, Y", strtotime($row['create_date']));?></td> <td> <!-- Icons --> <a href="<? echo base_url()?>admin/home/editCode/<?php print $row['id']?>" title="Edit"><img src="<? echo base_url()?>assets/images/icons/pencil.png" alt="Edit" /></a> <a href="<? echo base_url()?>admin/home/deleteCode/<?php print $row['id']?>" title="Delete" class="delete-code"><img src="<? echo base_url()?>assets/images/icons/cross.png" alt="Delete" /></a> </td> <?php endforeach;?>
原文:https://stackoverflow.com/questions/2115300
更新时间:2021-10-01 10:10
最满意答案
SELECT CAST(LEFT(CLOSE_PRICE,10) +'.' +RIGHT(CLOSE_PRICE,LEN(CLOSE_PRICE)-10) AS DECIMAL(10,2)) FROM [testTable]
没关系。 我测试的结果是19.90
SELECT CAST(LEFT(CLOSE_PRICE,10) +'.' +RIGHT(CLOSE_PRICE,LEN(CLOSE_PRICE)-10) AS DECIMAL(10,2)) FROM [testTable]
It would be fine. I tested the result is 19.90
相关问答
更多-
这应该涵盖你列出的所有情况,这不会处理一个月中不正确的日子(例如2月30天)但是仍然看起来有点hackish,在发送之前将数据转换为日期的任何方式? 编辑:交换大于标志少于标志编辑:愚蠢的程序员,我换出小于值,使他们比我想要的值高一个(> 12不包括12但是> 13)编辑:添加失踪'结束'声明 ,case when PSEFYR = 99 then '21' when PSEFCT = 0 then '19' else '20' end + case when PSEFYR < ...
-
SELECT CAST(LEFT(CLOSE_PRICE,10) +'.' +RIGHT(CLOSE_PRICE,LEN(CLOSE_PRICE)-10) AS DECIMAL(10,2)) FROM [testTable] 没关系。 我测试的结果是19.90 SELECT CAST(LEFT(CLOSE_PRICE,10) +'.' +RIGHT(CLOSE_PRICE,LEN(CLOSE_PRICE)-10) AS DECIMAL(10,2)) FROM [te ...
-
好吧它看起来像IPV4,所以我将继续这个假设。 您也转换为一些非常长的二进制文本表示,我建议您只使用BINARY(4) ,我的答案将假设。 如果你愿意,你可以将这个131个字符的文本表示转换成你,但我不知道你为什么要这样做。 几年前我在这里发布了一个类似的一般问题的答案: https : //stackoverflow.com/a/1385701/109122 这基本上显示了这个功能: CREATE FUNCTION dbo.fnBinaryIPv4(@ip AS VARCHAR(15)) RETURNS ...
-
看起来对我来说都是MONEY : SELECT CAST(Fare AS MONEY) FROM Table1 演示: SQL小提琴 完整查询: SELECT BookingDate ,COUNT(*) ,SUM(CAST(Fare AS MONEY)) FROM Table1 WHERE QuoteOrBooking = 'Quote' AND Fare IS NOT NULL GROUP BY BookingDate ORDER BY BookingDate ...
-
你可以尝试这样的事情,修改后供你使用: declare @YY int = 2016 declare @MM int = 5 select CAST(CAST(@YY as varchar(4)) + '-' + RIGHT('00' + CAST(@MM as varchar(2)),2) + '-01' as DATE) You could try something like this, modified for your use: declare @YY int = 2016 declare @M ...
-
很简单,首先添加整天,然后添加剩余的ms。 一天有86,400,000毫秒。 declare @unixTS bigint set @unixTS = 1359016610667 select dateadd(ms, @unixTS%(3600*24*1000), dateadd(day, @unixTS/(3600*24*1000), '1970-01-01 00:00:00.0') ) 结果是2013-01-24 08:36:50.667 Easy, first add whole da ...
-
您在查询中没有使用格式添加/删除前导零,因此它们不能在表中。 前导零只能存在于基于字符串的数据类型列中,并且只有在它们故意放在那里时才存在。 基于所有给定信息,我最好的猜测是Table1.CC_RENAL_SUPPORT_DAYS_1是一个char或varchar,并且在列中有前导零,而vw_FormatTable1。[CC_RENAL_SUPPORT_DAYS_1]是一个int(或没有前导零的char / varchar)。 如果您在第二个查询中需要前导零,请使用: select [CC_REN ...
-
为什么这个TSQL转换日期时间 - > varchar - > datetime?(Why does this TSQL cast datetime -> varchar -> datetime?)[2023-08-24]
这会将日期时间内的任何超时时间值截断,只留下日期值。 (关键是转换代码“103”。) This truncates any excess time-of-day value out of the datetime leaving just the date value. (The key is the conversion code "103".) -
基于TSQL的转换函数与基于实体框架的函数(Convert Function Based on TSQL with Function Based with Entity Framework)[2022-08-19]
当然,EF执行的时间比普通的旧SQL查询要长,而且你可以做的很少(除了编写最优的LINQ查询)。 有这样一个非常简单的原因。 运行一个直接的SQL命令只会发送回数据,没有任何麻烦,也没有附加任何大惊小怪,等待你进行数据操作,使其达到适合你想要的任何数据结构的程度。运行另一方面,EF意味着它不仅运行SQL命令,而且还会将数据按摩到您可以立即操作的对象中。 通过ADO.NET并将数据自动转换为对象的额外操作意味着它将花费更长时间而不仅仅是执行纯SQL查询。 然而,在硬币的另一面,EF确实提供了一种非常好的简单方 ... -
这是一个xy问题 。 用于GUID的正确数据类型是uniqueidentifier 。 无需自己将其转换为某种数值数据类型。 uniqueidentifier以16字节二进制格式存储,而不是显示的char(36)字符串。 This is an xy problem. The correct datatype to use for GUIDs is uniqueidentifier. There is no need to convert it to some numeric datatype yoursel ...