ianmc ianmc - 2 years ago 61
PHP Question

Selecting an array of rows using MySQLi

I'm trying to return results from an array of varying row numbers. Right now each row number in mysqli query is manually entered. How would you replace these values with the values of the


$currentUsers = array('1', '3', '7', '10');

while ($row = mysqli_fetch_array ($query))
$interestValue = ((int) "$row[1]") +
((int) "$row[3]") +
((int) "$row[7]") +
((int) "$row[10]");
echo "$interestValue";

Answer Source

Inside the while loop use the array like this:

$interestValue = 0;
foreach ( $currentUsers as $i ) {
    $interestValue = $interestValue + (int) $row[i];
echo $interestValue;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download