0

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
xh28
  • 11
  • 3
  • What result were you expecting? To only have 1 array with 18 values displayed? or to have 2 arrays with 18 values (and not NULL values in the case of the last array)? – Webeng Apr 21 '16 at 10:43
  • it doesn't really matter whether your failed query is within a loop or not. If it fails then there is an error. You just need to read the error message and then fix the error. – Your Common Sense Apr 21 '16 at 11:16
  • The following are all set but no error message: ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(E_ALL); Plus the following is set on connect statement. – xh28 Apr 21 '16 at 12:08
  • Can this be changed to not a duplicate please. I have added additional information which demonstrates that the issue is not about error reporting as this was already on and there are no error messages. In summary the first iteration completes the array successfully and in the second iteration $row 6 returns false but there are no error messages. – xh28 Apr 21 '16 at 16:20

0 Answers0