As a noob I am finding this hard to explain but essentially I execute a PDO query and get the results via fetchAll (I was using Fetch but there was a suggestion about open cursors so I changed to fetchAll to try and prevent this) and within that foreach I execute another query using some of the data from the first query.
There are two results from $query5 and the 1st iteration works okay but the second iteration loses pointers and returns Nulls.
I have tried lots of things here and it is driving me mad. This is my first post to Stackoverflow but I have used it lots and it nearly always gives me the answer I am looking for - heres hoping.
Code Extract
//initialise array
$parvalues = array();
//Start by getting the rounds played by player
$query5 = "select * from IN_holeresults
where ho_playerkey = :namekey ";
$stmt5 = $pdoconn->prepare($query5);
$stmt5->bindValue(':namekey', $namekey) ;
$stmt5->execute();
$results5 = $stmt5->fetchAll(PDO::FETCH_ASSOC);
foreach($results5 as $row5)
{
//fetch the course info i.e. the Par value
$query6 = "
select * from IN_events, IN_venues
where ev_venuekey = ve_key
and ev_number = :evnumber
and ev_year = :evyear
";
$stmt6 = $pdoconn->prepare($query6);
$stmt6->bindValue(':evnumber', $row5['ho_eventkey']) ;
$stmt6->bindValue(':evyear', $row5['ho_year']) ;
$stmt6->execute();
$row6 = $stmt6->fetch();
//loop round holes and get par values and store in array
for ($j=1; $j<=18; $j++)
{
$parvalues[$j] = $row6['ve_parh'.$j];
}
var_dump($parvalues);
}
Screen shop of Var_dump showing values in iteration 1 but nulls in int#2
Additional Information: I have the following in the code.
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);
plus
$pdoconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
As well I know that the first iteration works (so the SQL works at least on that first pass) as the screen image shows that there are values in the array. On the second iteration Xdebug shows row6 as false.
Any help on further debugging gratefully received.
Tony