我在使用php + mysql从数据库中提取信息时遇到问题,并认为如果有人在这里可能会提出一条出路,那将会很好。Php:通过mysql从数据库中获取结果集
问题的代码:
$selectedProtocols=array(1,2);
for($i = 0; $i<2; $i++)
{
$result = mysql_query("SELECT throughput FROM session where mainProtocol='$selectedProtocols[$i]'");
while($row = mysql_fetch_array($result))
{
$throughput_temp += $row['throughput'];
}
$selectedProtocols[$selectedProtocols[$i]]=$throughput_temp;
}
以下是有关数据库enteries:
mainProtocol name throughput
1 Skype 34
2 HTTP 43
1 FTP 54
现在,以下LOC给出正确的输出即(34 + 54 =)88
echo "1 has throughput=".$selectedProtocols[$selectedProtocols[0]]."<br>";
但是,下面的LOC给出输出为零而不是43
echo "2 has throughput=".$selectedProtocols[$selectedProtocols[1]]."<br>";
我认为在查询数据库时读取结果集的方法存在一些问题。任何想法我在做什么错误?
这解决了问题一点点,但现在我需要访问值只有当我知道钥匙想打印我必须键入值 回声“值:”。 $ SP [1]; 回声“价值:”。 $ SP [2]; 但问题是,我实际上没有在数组中只有2个项目:SP,而我有30至40个ID,因此我不想写30到40行来打印值。我可以用循环的帮助吗?这样我得到的输出为: 1的值是0 2的值是34 6的值是67 15的值是56 。 。 。当数组sp是(1 => 0,2 => 34,6 => 67,15 => 56 ...)时为 。 – baltoro 2009-10-13 04:58:55