我有学生订购的信息数据存储在数据库中。我想通过从日期和时间选择的下拉菜单来搜索这些订单。通常,我可以搜索数据库中的所有数据,但当我选择下拉列表从日期和时间选项时无法工作。
我的文件在下面:
SrchList.html.ep
<%
my $SrchResult = stash('SrchResult');
my $Date = stash('Date');
my @Date =(['--' => '']);
foreach my $key (sort keys %{$Date}){
push(@Date, ($Date->{$key}->{name}) => $key);
}
my $Time = stash('Time');
my @Time =(['--' => '']);
for(my $i = 1; $i <= $Time->{max}; $i++){
push(@Time, [$i.'H' => $i]);
}
%>
<form action="<%= url_for('/SrchList') %>" method="post" class="form-horizontal frmSrchList">
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="input-group">Order Start<%= select_field 'Date'=>\@Date, class=>'form-control', id=>'Date_start' %></div>
<div class="input-group">Time Start<%= select_field 'Time'=>\@Time, class=>'form-control', id=>'Time_start' %></div>
<div> ~ </div>
<div class="input-group">Order End<%= select_field 'Date'=>\@Date, class=>'form-control', id=>'Date_end' %></div>
<div class="input-group">Time End<%= select_field 'Time'=>\@Time, class=>'form-control', id=>'Time_end' %></div>
</div>
<div class="col-lg-10 col-lg-offset-1">
<button type="submit" class="btn btn-success">Search</button>
</div>
</div>
<div class="row"><table class="table table-striped">
<thead><tr><th>recptid</th><th>student_id</th><th>price</th><th>total</th><th>upd_date</th></tr></thead>
<tbody >
% foreach my $reserve_id (sort {$b <=> $a} keys %{$SrchResult}){
% $SrchResult->{$reserve_id}->{upd_date} =~ /(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
% $SrchResult->{$reserve_id}->{price} =~ s/\,/<br>/g;
<tr>
<td><%= uc($SrchResult->{$reserve_id}->{recptid}) %></td>
<td><%= uc($SrchResult->{$reserve_id}->{student_id}) %></td>
<td align="right"> <%== decode('utf-8', $SrchResult->{$reserve_id}->{price}) %> </td>
<td align="center"> <%== decode('utf-8', $SrchResult->{$reserve_id}->{total}) %></td>
<td> <%= decode('utf-8', $SrchResult->{$reserve_id}->{upd_date}) %> </td>
</tr>% }
</tbody>
</table></div>
</form>
索引.cgi
get '/SrchList'=>{page => undef} => sub {
my $self = shift;
my @breadcrumb = ('SrchList');
$self->stash('breadcrumb'=> \@breadcrumb);
my $Date = $TextBookCommon->GetDate();
$self->stash('Date' => $Date);
$self->stash('Time' => $TextBookCommon->{'CONFIG'}->{'SELECT'}->{'Time'});
$session->clear('_SRCH_DATA');
$self->render('SrchList');
};
post '/SrchList/:page' => {page => undef} => sub {
my $self = shift;
my @breadcrumb = ('SrchList');
$self->stash('breadcrumb'=> \@breadcrumb);
my %SRCH_DATA = (defined $session->param('_SRCH_DATA') ? %{$session->param('_SRCH_DATA')} : '');
my $Date;
my $Time;
if(! defined $self->param('return')){
$Date = ($self->param('Date') ne '' ? $self->param('Date') : $Date);
$Time = ($self->param('Time') ne '' ? $self->param('Time') : $Time);
} else {
$Date = (exists($SRCH_DATA{'Date'}) ? $SRCH_DATA{'Date'} : '');
$Time = (exists($SRCH_DATA{'Time'}) ? $SRCH_DATA{'Time'} : '');
}
my $SrchData = {
'Date' => $Date,
'Time' => $Time
} ;
my $DateData = $TextBookCommon->GetDate();
$session->param(-name=>'_SRCH_DATA', -value=>$SrchData);
my $SrchResult = $TextBookCommon->GetOrderSearch($SrchData);
$self->stash('Date' => $DateData);
$self->stash('Time' => $TextBookCommon->{'CONFIG'}->{'SELECT'}->{'Time'});
$self->stash('SrchResult'=> $SrchResult);
$self->stash('SrchData'=> $SrchData);
$self->stash('TextBookCommon' => $TextBookCommon);
$self->render('SrchList');
};
索引.cgi.conf
{
'SELECT' => {
'Time' =>{
'max' => 24
},
},
}
TextBookCommon.pm
sub CreateOrderSearchSQL(){
my $self = shift;
my $StudentData = shift;
my $Date_start = $StudentData->{Date_start};
my $Time_start = $StudentData->{Time_start};
my $Date_end = $StudentData->{Date_end};
my $Time_end = $StudentData->{Time_end};
my $sql;
my $dbh = $self->{'dbh'};
my $data = '';
my @param = ();
$sql =<<" SQL_EOL";
SELECT tr.reserve_id, tr.recptid, tr.student_id, GROUP_CONCAT(tr.price) AS 'price',
SUM(tr.price)+1000 AS 'total', tr.upd_date AS 'upd_date'
FROM
( SELECT ra.reserve_id, RIGHT(ra.reserve_id,5) AS recptid,
m.student_id, rb.price, rb.upd_date FROM t_reserve_a AS ra
INNER JOIN t_reserve_b AS rb ON ra.reserve_id=rb.reserve_id
INNER JOIN m_student AS m ON m.student_id=ra.student_id ) AS tr
GROUP BY tr.reserve_id
SQL_EOL
if($Date_start ne '' || $Date_end ne ''){
$sql .="and WHERE DATE(t_reserve_a.upd_date) BETWEEN DATE(t_reserve_a.upd_date) = ? AND DATE(t_reserve_a.upd_date) =?";
push(@param, $Date_start, $Date_end);
}
if($Time_start ne '' || $Time_end ne ''){
$sql .="and WHERE TIME(t_reserve_a.upd_date) BETWEEN TIME(t_reserve_a.upd_date) = ? AND TIME(t_reserve_a.upd_date) = ? ";
push(@param, $Date_start, $Date_end);
}
my $result = {
'sql' => $sql,
'param' => \@param,
};
return $result;
}
sub GetOrderSearch(){
my $self = shift;
my $StudentData = shift;
my $result = $self->CreateOrderSearchSQL($StudentData);
my $sql = $result->{'sql'};
my @param = @{$result->{'param'}};
$sql .= " order by tr.reserve_id ";
my $SrchResult = $dbh->selectall_hashref($sql,'reserve_id',undef, @param);
return $SrchResult;
}
谁能帮我解决这个问题?