I am encountering a problem while extracting info from a database using php+mysql and thought it will be good if somebody here may suggest a way out.
Problematic Code:
$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;
}
Following are the concerned database enteries:
mainProtocol name throughput
1 Skype 34
2 HTTP 43
1 FTP 54
Now, following LOC gives correct output i.e. (34+54=) 88
echo "1 has throughput=".$selectedProtocols[$selectedProtocols[0]]."<br>";
But, following LOC gives ouput as zero instead of 43
echo "2 has throughput=".$selectedProtocols[$selectedProtocols[1]]."<br>";
I think there is some problem with method of fetching the result set while querying database. Any idea what wrong am I doing?