我有项目表,其中的列为:
还有一个名为 ctgr 的表,其中的列为:
现在编码显示的产品如下:
但是我想显示如下产品:
汽车
公交车
卡车
来自index.cgi :
sub action_index {
my $self = shift;
$self->set_property(paginate_row_count => 0);
my $m_item = $self->model('item');
$self->set_data(
'ctgrs',
$self->model('ctgr')->get_list('del_flg = 0 and show_web = 1')
);
$m_item->set_input_params;
$self->search_execute($m_item->get_list_sql->where("v_item.item_flg = 1"));
$self->set_data('cart',$self->get_list_cart);
}
来自index.html :
<table>
[% if(@{$c{list}}>0) %]
[% foreach my $rec (@{$c{list}}) %]
[% if($rec->{is_item_public}==1) %]
[% foreach my $i (@{$c{list}}-1) %]
<tr>
<td align="center">
[# $rec->{ctgr_name} #]
</td>
</tr>
[% end %]
<tr>
<td class="item">
[# $rec->{item_id} #]<br>
[# $rec->{item_name} #]<br>
</td>
</tr>
[% end %]
[% end %]
[% else %]
<tr>
<td>no data</td>
</tr>
[% end %]
</table>
来自文件??
sub search_execute {
my $self = shift;
my $sql = shift;
my @wheres = ();
foreach my $key (keys %{$self->{search_params}}){
my $value = $self->param("search/${key}");
if(defined $self->{search_params}->{$key}->{func}){
$self->{search_params}->{$key}->{func}($sql,$value);
}
elsif (defined $value && $value ne '') {
my $type = defined $self->{search_params}->{$key}->{type}
? $self->{search_params}->{$key}->{type}
: '= ?';
my $field = defined $self->{search_params}->{$key}->{field}
? $self->{search_params}->{$key}->{field}
: $key;
$value =~s/^\s+//;
$value =~s/\s+$//;
my @where_or = ();
foreach (split(/\s+/,$value)) {
my $replace = $self->{search_params}->{$key}->{replace} || '?';
$replace =~ s/\?/$_/;
push @where_or, ["${field} ${type}",$replace];
}
if ($self->{is_search_where_or}) {
push @wheres,@where_or;
}
else {
$sql->where_or( @where_or );
}
}
elsif ( defined $self->{search_params}->{$key}->{default} ) {
my $field = $self->{search_params}->{$key}->{field} || $key;
my $type = $self->{search_params}->{$key}->{type} || '= ?';
if( $self->{is_search_where_or} ) {
push @wheres,
["${field} ${type}", $self->{search_params}->{$key}->{default}];
}
else{
$sql->where(
["${field} ${type}", $self->{search_params}->{$key}->{default}] );
}
}
}
if( $self->{is_search_where_or} ) {
$sql->where_or(@wheres) if(@wheres);
}
my $tmp_orderby = $sql->{ORDERBY};
$sql->{ORDERBY} = [];
my $total = $sql->get_count(@_);
if($total>0){
my $page = $self->param('page') || 1;
$page = 1 unless(($page=~/^\d+$/) && $page>=1);
my $offset = ($page-1)*$self->{paginate_row_count};
$sql->{ORDERBY} = $tmp_orderby;
if($self->{paginate_row_count}>0){
$sql->limit($offset,$self->{paginate_row_count});
}
my $sth = $sql->execute(@_);
my @data = ();
while(my $ra = $sth->fetchrow_hashref){
$self->filter_in_all($ra);
push @data,$ra;
}
$self->set_data('list',\@data);
}
}