效果如下
代码如下:
{eyou:sql sql='select * from ey_guestbook_attr'} {eyou:assign name="ycnh" value="$i"} <div class="txt"> {eyou:sql sql='select * FROM ey_guestbook_attr where aid=$ycnh && attr_id=1'} <h2>留言人:{$field.attr_value}</h2> {/eyou:sql} {eyou:sql sql='select * FROM ey_guestbook_attr where aid=$ycnh && attr_id=2' id="field2"} <div class="sub"> <span><i class="am-icon-clock-o"></i>联系电话:{$field2.attr_value}</span> <span><i class="am-icon-clock-o"></i>留言时间:{$field2.add_time|MyDate='Y-m-d h:i:s',###}</span> </div> {/eyou:sql} {eyou:sql sql='select * FROM ey_guestbook_attr where aid=$ycnh && attr_id=3' id="field3"} 留言内容:{$field3.attr_value} {/eyou:sql} </div> {/eyou:sql}
网友的写法:
带手机号加密:
{eyou:php} $a = \think\Db::name('guestbook')->limit('0,10')->order('aid desc')->select(); $attr_list = array(); foreach ($a as $key => $val) { $aid = \think\Db::name('guestbook_attr')->where('aid',$val['aid'])->select(); $attr_lists = array(); foreach ($aid as $k => $v) { $attr_lists[$v['attr_id']] = $v['attr_value']; } $attr_lists['299'] = $val['add_time']; $attr_list[] = $attr_lists; } foreach ($attr_list as $key => $val) { $time = date('Y-m-d H:i:s',$val['299']); $phone = str_split($val['26']); $moblie = array(); foreach ($phone as $k => $v) { if ($k > 2 && 7 > $k) { $moblie[] = '*'; } else { $moblie[] = $v; } } $moblies = implode('', $moblie); echo '<li>'; echo '<div class="sli_item">'; echo '<div>'; echo '<div class="announ_tit">留言列表</div>'; echo '<i class="1">姓名:'.$val['24'].'</i> <i class="2">电话:'.$phone.'</i> <i class="3">留言内容:'.$val['25'].'</i> <i class="4">留言时间:'.$time.'</i>'; echo '</div>'; echo '</div>'; echo '</li>'; } {/eyou:php}
将上面“val[24]”数字修改为自己网站的数据库表名“ey_guestbook_attr”,对应attr_id;