在php中循环结果集

I am new to php and i am using PDO for db operations

through a query i get the result set which is printed using print_r() function

Output looks like

Array
(
[0] => Array
    (
        [selection_id] => 8947562
        [price_difference] => 1.02
        [one_miniute_price] => 4.20
        [one_min_pc] => 0.2381
    )

[1] => Array
    (
        [selection_id] => 8801685
        [price_difference] => 1.00
        [one_miniute_price] => 13.50
        [one_min_pc] => 0.0741
    )

[2] => Array
    (
        [selection_id] => 9464307
        [price_difference] => 1.00
        [one_miniute_price] => 11.00
        [one_min_pc] => 0.0909
    )

[3] => Array
    (
        [selection_id] => 9066075
        [price_difference] => 0.99
        [one_miniute_price] => 1.99
        [one_min_pc] => 0.5025
    )

[4] => Array
    (
        [selection_id] => 8726674
        [price_difference] => 0.95
        [one_miniute_price] => 10.50
        [one_min_pc] => 0.0952
    )

)

Now my problem is that i want to loop though this output and access the columns for each record

Any help is highly appreciated

regards

foreach($array as $result) {
    echo $result["selection_id"];
}

The fact that your using a PDO leads to to think that your problem is that the data is tied up in an object and you need to use some "fetch" or "get" function to release them.

If, however, that is the exact result of print_r() then does this not work?

<?php
foreach($results as $someResult){
    echo $someResult['selection_id'] . '<br>';
    echo $someResult['price_difference'] . '<br>';
    echo $someResult['one_miniute_price'] . '<br>';
    echo $someResult['one_min_pc'] . '<br>';

    echo "<hr>";
}
?> 

Obviously change $results to whatever the object name is.

Get all variable values by using for loop and write sql insert query in loop.

for (i=0; $i < count($arr);$i++){
    $selection_id = $arr[$i][selection_id];
    ....
    ....
    ....
}

the answer is in your question: "foreach"

foreach($resultSet as $row)
{
    //do your logic with the record ($row)
}