PHP显示基于昨天和今天的数据(PHP show data based on Yesterday and Today)
我有一个关于根据日期显示数据表的问题。 在这种情况下,我想根据今天和昨天显示数据。
设计表:
form_no | model_name | prod_status | 添加日期示例数据:
1 | acer | 好的| 12-APR-2013
2 | acer | NG | 11-APR-2013所以如果在表格中我只想让数据显示一次,因为型号名称是相同的。 表视图像这样
没有| 模型| 昨天状态| 今日状态
1 | acer | NG | 好这里是我的代码:
$today = date("j-F-Y"); $yesterday = date("j-F-Y, time() - 60 * 60 * 24;"); $query = "SELECT model_name, prod_status, date_added FROM t_production_status WHERE date_added like '$today%'"; $result = mysql_query($query);
现在我在桌面上完成了今天的数据显示,现在我想将昨天的状态显示到表格视图中。
I have an question about show data table based on date. In this case I want to show data based on today and yesterday.
Design table :
form_no | model_name | prod_status | date_addedExample data :
1 | acer | OK | 12-APR-2013
2 | acer | NG | 11-APR-2013So if in table I just want the data will show once, because the model name is same. Table view Like this
No | Model | Yesterday Status | Today Status
1 | acer | NG | OKand here is my code :
$today = date("j-F-Y"); $yesterday = date("j-F-Y, time() - 60 * 60 * 24;"); $query = "SELECT model_name, prod_status, date_added FROM t_production_status WHERE date_added like '$today%'"; $result = mysql_query($query);
Now I'm done show data by today in table, now I want to display yesterday status to table view.
原文:https://stackoverflow.com/questions/16230325
最满意答案
这行代码有一些很容易发生的潜在问题
scanf("%s",&pattern);
你可以让它像这样安全一点
scanf("%6s",&pattern);
这是一个
6
因为你需要在字符串的末尾添加一个额外的字节'\0'
,这将我们带到下一个问题for(i=0;i<7;i++)
在这里你假设所有字节都是非
nul
,除了你正在用scanf()
读取一个字符串,除非你创建的数组比你想要存储在其中的字符数大一个字节,scanf()
会溢出数组,即写一个字节超出它的界限。将
"%6s"
长度说明符添加到格式字符串可解决此问题,但您只能在数组中存储6
非nul
字节,而对于另一个问题for (i = 0 ; pattern[i] != '\0' ; i++)
会更好,因为您不需要事先知道字符串的长度,也不会冒险读取数组的末尾。
尝试这个:
#include <stdio.h> int main(void) { char letter; char c; int i; char pattern[7]; printf("Enter a letter: "); if (scanf(" %c",&letter) != 1) { printf("error: invalid input.\n"); return -1; } printf("Enter a pattern: "); if (fgets(pattern, sizeof(pattern), stdin) == NULL) { printf("error: end of file.\n"); return -1; } for (i = 0 ; pattern[i] != 0 ; ++i) { if (letter == pattern[i]) { c++; printf("Letter < %c > is found in pattern %s\n", letter, pattern); printf("in adress: %p\n", pattern + i); printf("index :%d\n", i); } } if (c == 0) printf("The pattern does not include any letter"); return 0; }
你也错误地打印了地址,因为在
pointer[i]
下标操作符取消引用指针,它相当于*(poitner + i)
。This line of code has some potential problem that can easily happen
scanf("%s",&pattern);
you can make it a little bit safer like this
scanf("%6s",&pattern);
it's a
6
because you need one extra byte'\0'
at the end of the string, which takes us to the next problemfor(i=0;i<7;i++)
here you are assuming that all bytes are non-
nul
which would be ok except that you are reading a string withscanf()
and unless you create the array one byte bigger than the number of characters you want to store in it,scanf()
will overflow the array i.e. write a byte beyond it's bounds.Adding the
"%6s"
length specifier to the format string solves this, but you can only store6
non-nul
bytes in the array, and for the other problemfor (i = 0 ; pattern[i] != '\0' ; i++)
would be better, because you don't need to know the length of the string in advance and you don't risk reading past the end of the array.
Try this:
#include <stdio.h> int main(void) { char letter; char c; int i; char pattern[7]; printf("Enter a letter: "); if (scanf(" %c",&letter) != 1) { printf("error: invalid input.\n"); return -1; } printf("Enter a pattern: "); if (fgets(pattern, sizeof(pattern), stdin) == NULL) { printf("error: end of file.\n"); return -1; } for (i = 0 ; pattern[i] != 0 ; ++i) { if (letter == pattern[i]) { c++; printf("Letter < %c > is found in pattern %s\n", letter, pattern); printf("in adress: %p\n", pattern + i); printf("index :%d\n", i); } } if (c == 0) printf("The pattern does not include any letter"); return 0; }
You also was printg the address wrong, because in
pointer[i]
the subscript operator dereferences the pointer, it's equivalent to*(poitner + i)
.
相关问答
更多-
char*和char[] 是不同的类型 ,但在所有情况下都不会立即显现。 这是因为数组衰减为指针 ,这意味着如果预期类型为char*的类型为char[]的表达式,则编译器将自动将该数组转换为指向其第一个元素的指针。 你的例子函数printSomething需要一个指针,所以如果你尝试像这样传递一个数组: char s[10] = "hello"; printSomething(s); 编译器假装你写这个: char s[10] = "hello"; printSomething(&s[0]); char ...
-
有时,数组的名称会衰减为指向其第一个元素的指针。 具有数组类型的表达式将在数组类型不合法时转换为指针,但指针类型为。 你做不到: arr++; 因为数组是不可修改的l值。 The name of an array decays to an pointer to its first element sometimes. An expression with array type will convert to a pointer anytime an array type is not legal, but ...
-
void foo(char *test) { /* Please note, you need to add one extra byte here for a terminator */ char a[2] = {0}; char b[2] = {0}; char c[2]= {0}; memcpy(&a,&test[0],1); memcpy(&b,&test[1],1); memcpy(&c,&test[2],1); cout << a <我相信这是最佳方式,因为只有一个动态分配,减少了堆碎片的开销和分配所需的时间。 您可以使用STRING_INDEX实用程序函数来访问第n个字符串。 此外,使用calloc()而不是malloc()将缓冲区清零以确保所有字符串都已终止NUL。 #define STRING_SIZE 10000000 #define NUM_STRINGS 10 #define STRING_INDEX(array, string_idx) ((array) + (string_idx) * STRING_SIZE) in ...读取C声明符(这是*和[]的变量的一部分)是相当细微的。 有一些网站的提示: http://www.antlr.org/wiki/display/CS652/How+To+Read+C+Declarations http://www.ericgiguere.com/articles/reading-c-declarations.html char**是指向(可能多个)指针的指针(可能多个)char(s)。 例如,它可能是一个指向字符串指针的指针,或者是一个指向字符串指针数组的指针。 char*[]是指向ch ...
C中的字符数组指针(Char array pointer in C)[2023-07-20]
这行代码有一些很容易发生的潜在问题 scanf("%s",&pattern); 你可以让它像这样安全一点 scanf("%6s",&pattern); 这是一个6因为你需要在字符串的末尾添加一个额外的字节'\0' ,这将我们带到下一个问题 for(i=0;i<7;i++) 在这里你假设所有字节都是非nul ,除了你正在用scanf()读取一个字符串,除非你创建的数组比你想要存储在其中的字符数大一个字节, scanf()会溢出数组,即写一个字节超出它的界限。 将"%6s"长度说明符添加到格式字符串可解决 ...在C中传递字符指针(Passing char pointer in C)[2022-05-25]
void ptrch ( char * point) { point = "asd"; } 您的指针按值传递 ,并且此代码将复制,然后覆盖副本 。 所以原始的指针是不变的。 PS要指出的是,当你做point = "blah"你正在创建一个字符串文字,并且任何修改的尝试都是Undefined behavior ,所以它应该是const char * 修复 - 像@Hassan TM那样传递一个指向指针的指针 ,或者像下面那样返回指针 。 const char *ptrch () { retu ...无法比较char数组与char C中的指针数组[关闭](Can't compare char array vs char array of pointer in C [closed])[2022-04-08]
我已经修改了你的程序,它运行得很好。 我有 使用空指针终止单词列表,这样我们就不依赖于数字。 使用strcmp 。 从stdin而不是从文件中读取(预期输入是一个简单的单词系列,可能与也可能不匹配一个停用词)。 引入了一个“找到”标志和一个中间循环中断,而不是在循环条件下进行比较(这样,如果找到的话我们可以做到这一点)。 程序: #include#include char* someWords[]= { "a", "about", "above","ac ... C语言char指针变量值为非指针字符数组值?(C language char pointer variable value to non pointer char array value?)[2022-01-19]
您需要将mycustomstring的内容复制到myb64 。 strcpy是这样做的函数。 例如 char *mycustomstring = "TXkgYm9ubmllIGlzIG92ZXIgdGhlICAgICAgICAgIA=="; char myb64[1024]; strcpy(myb64, mycustomstring); you need to copy the contents of mycustomstring to myb64. strcpy is the function that ...为什么C ++中的C字符串和Char数组和Char指针存在差异(Why the C string and Char Array and Char pointer differences in C++)[2022-05-16]
C字符串只不过是一个字符数组。 因此,除了您的工作示例,您还可以执行以下操作: const char cString[] = "Hello world"; 这基本上相当于: const char cString[] = { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; 请注意,这是一个char数组,而不是一个char 。 你遇到这个问题的原因: const char cString = "Hello world"; 是因为"Hello ...相关文章
更多- 每日英语:7 Important Questions to Ask Yourself Today
- Becoming a data scientist
- 《Big Data Glossary》笔记
- Spring Data: a new perspective of data operations
- data-config
- (二)solr data import
- zz Data Analysis Process
- The Log: What every software engineer should know about real-time data's unifying abstraction
- Spring Data Solr教程(翻译)
- 自己封装的一个Solr Data Import Request Handler Scheduler
最新问答
更多- 您如何使用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)