表格1
id | author | number_of_view |
---+--------------+-----------------
1 | john | 10
2 | Jack | 20
3 | Anna | 80
4 | Neri | 100
下面我有一个 PHP 脚本,它检查 MySQL 数据库表并向用户提供徽章。该脚本完美运行。
$from1=10;
$to1=15;
$from2=20;
$to2=30;
$query=mysql_query("SELECT SUM( number_of_view ) AS view_number, author FROM `table1` GROUP BY author");
while ($row= mysql_fetch_array($query))
{
$view_number=$row['view_number'];
$author=$row['author'];
if ($viewnumber>$from1 && $viewnumber<=$to1)
{
echo "special user";
}
elseif ($viewnumber>$from2 && $viewnumber<=$to2)
{
echo "plain user";
}
}
}
但问题是我想从数据库表中获取$from
变量$to
值:
表2
id | badge | from |to
---+-------------+------+---
1 | special user| 10 |15
2 | plain user | 20 |30
这是第二个表的第二个查询和 PHP 脚本:
$query2=mysql_query("SELECT * FROM table2");
while ($row= mysql_fetch_array($query2)) {
$badgeName=$row['view_number'];
//I would like to use this variable above. So instead of "echo 'special user';" I would like use "echo $badgeName" $from=$row['author'];
// I would like to use this variable above instead of $from1 and $from2 $to=$row['to'];
// I would like to use this variable above instead of $to1 and $to2 }
我怎样才能做到这一点?