5 回答
TA贡献1805条经验 获得超9个赞
sql:
select a.value,a.data1,a.data2,a.period,b.name,b.main_url from 表2 a,表1 b where
a.period in (1,2,3) and a.name=nb_visits and a.idsite = b.idsite order
by a.value desc;
代码:
<td><div><?php echo $row['name']?></div></td>
<td><div><?php echo $row['main_url']?></div></td>
<td><div><?php if($row['period'] == 1){echo $row['value'];} ?></div></td> 当period=1的时候 输出value??
<td><div><?php if($row['period'] == 2){echo $row['value'];}?></div></td>当period=2的时候 输出value??
<td><div><?php if($row['period'] == 3){echo $row['value'];}?></div></td>当period=3的时候 输出value??
TA贡献1828条经验 获得超6个赞
$sql = "select * form 表名 where name='nb_visits' and period in (1,2,3) order by value desc";
$res = mysql_query($sql);
while($result = mysql_fetch_array($res)){
if($result['period'] == 1){
echo '<td><div align="center">'.$row['value'].'</div></td>';
}
if($result['period'] == 2){
echo '<td><div align="center">'.$row['value'].'</div></td>';
}
if($result['period'] == 3){
echo '<td><div align="center">'.$row['value'].'</div></td>';
}
}
TA贡献1805条经验 获得超10个赞
TA贡献1876条经验 获得超7个赞
select * form 表名 where name='nb_visits' and period in (1,2,3) order by value desc
或者
select * form 表名 where name='nb_visits' and (period=1 or period=2 or period=3) order by value desc
TA贡献1712条经验 获得超3个赞
你指的 period 这个变量是一个数组,还是一个单独值?
如果是数组:
$period = array(1,2,3);
$period_str = implode(',',$period);
select * form 表名 where name='nb_visits' and period in (".$period_str.") order by value desc
如果是一个单独的值
$period = 1;
select * form 表名 where name='nb_visits' and period=".$period." order by value desc
添加回答
举报