首页 \ 问答 \ PHP foreach,if语句(PHP foreach, if statement)

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 ...
  • 这会将日期时间内的任何超时时间值截断,只留下日期值。 (关键是转换代码“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".)
  • 当然,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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)