5 回答

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超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> 當(dāng)period=1的時(shí)候 輸出value??
<td><div><?php if($row['period'] == 2){echo $row['value'];}?></div></td>當(dāng)period=2的時(shí)候 輸出value??
<td><div><?php if($row['period'] == 3){echo $row['value'];}?></div></td>當(dāng)period=3的時(shí)候 輸出value??

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超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貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個贊
<?php
$period = $_GET['period'];
$result = mysql_query("select * form 表名 where name='nb_visits' and period=" .$period. " order by value desc");
while($row = mysql_fetch_array($result))
{
?>
<td><div align="center"><?php echo $row['value']?></div></td>
<?php } ?>
大概這個意思,前面連接數(shù)據(jù)庫代碼沒寫,這是最基礎(chǔ)中的基礎(chǔ)了應(yīng)該不用我教

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超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貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個贊
你指的 period 這個變量是一個數(shù)組,還是一個單獨(dú)值?
如果是數(shù)組:
$period = array(1,2,3);
$period_str = implode(',',$period);
select * form 表名 where name='nb_visits' and period in (".$period_str.") order by value desc
如果是一個單獨(dú)的值
$period = 1;
select * form 表名 where name='nb_visits' and period=".$period." order by value desc
添加回答
舉報(bào)