我从html中的日期控件中获取到了自己当前选择所要查询的日期,然后再用这个日期到mysql数据库中去查询,最后把查询到的东西打印出来。
我想问,我从html中获取到了选择的日期过后,这个日期是变化的。怎么把这个运用到数据库的查询上面呢? 我用的是cgi 对mysql数据库的操作。
#include <stdio.h>
#include <cgi.h>
#include <session.h>
#include "gateway/h/log_db.h"
#include "/usr/include/mysql/mysql.h"
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user ="root";
char *password ="";
char *database = "gateway";
char *buf;
int main(void)
{
cgi_init();
cgi_session_start();
cgi_process_form();
char *p1;
char *p2;
cgi_init_headers();
cgi_include("log.htm");
p1=cgi_param("beginTime");   //p1 ,p2,是我从html上获取到的日期
p2=cgi_param("endTime");   //
//printf("begintime is :%s",p1);   // 获取成功!
# if 0
if(cgi_param("beginTime")&&cgi_param("endTime") )
{
printf("2013/05 16");//打印出那个时间段的日志
printf("2013/05 16");//打印出那个时间段的日志
printf("2013/05 16");//打印出那个时间段的日志
printf("2013/05 16");//打印出那个时间段的日志
printf("2013/05 16");//打印出那个时间段的日志
}
if(cgi_param("Ten"))
{

#endif

cgi_end();
return 0;
}
void test(void)
{
conn = mysql_init(NULL);
mysql_real_connect(conn,server,user,password,database,0,NULL,0);
mysql_query(conn,"select * from dev_log where logtime_from between '2013-06-20' and '2013-06-31'");   // 怎么把这个2013-06-20 和 2013-06-31 换成一个变量呢? 我每一次选择的日期不同。 就是一个根据一个日期段来查询数据
res = mysql_use_result(conn);
int num = mysql_num_fields(res);
while((row = mysql_fetch_row(res)) != NULL)
{
int i = 0 ;
for(i = 0 ;i< num; i++)
{
printf("%s",row[i]);
}
printf("\n");
}
mysql_free_result(res);
mysql_close(conn);
mysql_server_end();
}求各位大神指导, 我是小白 如果能加我QQ更好了!