0

I am creating functions and calling them after in index.php. Other parts work, but when I try to create function for this code and call, nothing returns, page is blank. Original code in index.php:

$abfrage1 = "SELECT c.area_id,c.title as comptitle,ta.name as taname,tb.name as tbname,m.date,m.time,scli.type as scli_type,scgo.type as scgo_type,m.match_id,m.status,m.match_id,m.final_period,a.country_code,u.user_name,m.team_a_id,m.team_b_id,m.score_a,m.score_b,s.competition_id,ROUND( TIMESTAMPDIFF(MINUTE, concat(m.date,' ',m.time),NOW() )) AS minutes_delay
FROM `match` m 
INNER JOIN round r ON m.round_id = r.round_id
INNER JOIN season s ON r.season_id = s.season_id
INNER JOIN round_coverage sc ON sc.round_id = r.round_id AND sc.coverage_type_id = '1' AND sc.type = 'Live'
$coverage_join
INNER JOIN competition c ON s.competition_id = c.competition_id
INNER JOIN users_comp uc ON c.competition_id = uc.competition_id
INNER JOIN area a ON c.area_id = a.area_id
INNER JOIN team ta ON ta.team_id = m.team_a_id
INNER JOIN team tb ON tb.team_id = m.team_b_id
LEFT JOIN users_match um ON um.match_id = m.match_id
LEFT JOIN users u ON um.user_id = u.user_id
LEFT JOIN match_checks mc ON mc.match_id = m.match_id
$innerjoin1
WHERE m.date <= DATE_ADD(CURDATE(),INTERVAL 1 DAY)  AND uc.user_id = '$userid' AND m.date >= DATE_SUB(CURDATE(),INTERVAL 2 DAY) AND m.date > '2014-11-30' AND m.status NOT IN  ('Postponed','Awarded','Cancelled') AND ((scgo.round_id > 0 AND mc.recheck1 IS NULL AND mc.recheck2 IS NULL) OR (scgo.round_id IS NULL AND concat(m.date,' ',m.time) > DATE_SUB(NOW(),INTERVAL 160 MINUTE)))
GROUP BY m.match_id
ORDER BY m.date ASC,m.time ASC,c.area_id ASC,r.season_id ASC,ta.name ASC"; 

$ergebnis1 = $dbh->query($abfrage1);
while ($row1 = $ergebnis1->fetch(PDO::FETCH_OBJ)) {
    //Other queries
}

In this query are two more variables:

$coverage_join :

if ($filter == 'liveli') {
$coverage_join = "INNER JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5' AND scli.type = 'Pre-Match'
INNER JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'  AND scgo.type = 'Live'";
} else {
$coverage_join = "LEFT JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5'
LEFT JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'";
}

$innerjoin1:

if ($uid > 0) { $innerjoin1 = "INNER JOIN users_match umm ON umm.match_id = m.match_id AND umm.user_id = '$uid'"; }
else { $innerjoin1 = ""; }

I created new storage.php and created function:

public function getMain($coverage_join, $innerjoin1, $userid)
    {
        $query = "SELECT c.area_id,c.title as comptitle,ta.name as taname,tb.name as tbname,m.date,m.time,scli.type as scli_type,scgo.type as scgo_type,
                        m.match_id,m.status,m.match_id,m.final_period,a.country_code,u.user_name,m.team_a_id,m.team_b_id,m.score_a,m.score_b,s.competition_id,
                        ROUND( TIMESTAMPDIFF(MINUTE, concat(m.date,' ',m.time),NOW() )) AS minutes_delay
                    FROM `match` m 
                    INNER JOIN round r ON m.round_id = r.round_id
                    INNER JOIN season s ON r.season_id = s.season_id
                    INNER JOIN round_coverage sc ON sc.round_id = r.round_id AND sc.coverage_type_id = '1' AND sc.type = 'Live'
                    :cJoin
                    INNER JOIN competition c ON s.competition_id = c.competition_id
                    INNER JOIN users_comp uc ON c.competition_id = uc.competition_id
                    INNER JOIN area a ON c.area_id = a.area_id
                    INNER JOIN team ta ON ta.team_id = m.team_a_id
                    INNER JOIN team tb ON tb.team_id = m.team_b_id
                    LEFT JOIN users_match um ON um.match_id = m.match_id
                    LEFT JOIN users u ON um.user_id = u.user_id
                    LEFT JOIN match_checks mc ON mc.match_id = m.match_id
                    :iJoin
                    WHERE m.date <= DATE_ADD(CURDATE(),INTERVAL 1 DAY)  AND uc.user_id = :uId AND m.date >= DATE_SUB(CURDATE(),INTERVAL 2 DAY) AND m.date > '2014-11-30' AND m.status NOT IN  ('Postponed','Awarded','Cancelled') AND ((scgo.round_id > 0 AND mc.recheck1 IS NULL AND mc.recheck2 IS NULL) OR (scgo.round_id IS NULL AND concat(m.date,' ',m.time) > DATE_SUB(NOW(),INTERVAL 160 MINUTE)))
                    GROUP BY m.match_id
                    ORDER BY m.date ASC,m.time ASC,c.area_id ASC,r.season_id ASC,ta.name ASC";
        $statement = $this->db->prepare($query);
        $statement->execute([
            ':cJoin' => $coverage_join,
            ':iJoin' => $innerjoin1,
            ':uId' => $userid,
        ]);
        return $statement->fetchObject();
    }

in index.php I put:

if ($uid > 0) { $innerjoin1 = "INNER JOIN users_match umm ON umm.match_id = m.match_id AND umm.user_id = '$uid'"; }
else { $innerjoin1 = ""; }


if ($filter == 'liveli') {
$coverage_join = "INNER JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5' AND scli.type = 'Pre-Match'
INNER JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'  AND scgo.type = 'Live'";
} else {
$coverage_join = "LEFT JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5'
LEFT JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'";
}

while ($row1 = $storage_access->getMain($coverage_join, $innerjoin1, $userid)) {
 // Other query
}

"$storage_access" is working properly, other queries that I am calling with functions work. I am not able to find solution to this problem, I hope you can give me any idea why it does not work. THanks in advance.

Edit: there are some function in the while{} loop that use $row1, for example:

$row11 = $storage_access->getGoalScorersA($row1);
S.Kav
  • 65
  • 6
  • What troubleshooting have you done? For example, PDO::query returns a PDOStatement on success and FALSE on failure. Did you check that PDO::query returned a PDOStatement? If it didn't, did you try to obtain an error code/message from PDO? What about error_reporting/logging? did you get any error messages in your logs or displayed in your browser/console? – GordonM Apr 15 '16 at 10:57
  • A blank page in PHP, not output when output is otherwise expected means you likely had a fatal error in code. Always when developing and testing code, at the top of your script `error_reporting(E_ALL); ini_set('display_errors', 1);` – Michael Berkowski Apr 15 '16 at 10:57

0 Answers0