I get a NULL value from var_dump when assigning a variable to an array in my select query

108 Views Asked by At

I have written a SELECT Query to concatenate a person's name and email address. I then want to echo this string.

Here is the code:

$sqldiv = "Select concat(p1.display_name, " - ", p1.user_email) AS Contact FROM wp_players p1
    JOIN wp_divisions2 d2 ON p1.id = d2.div_player1_id
    JOIN wp_leagues lg ON d2.div_league_ID = lg.league_id
    WHERE d2.player_div_id = 2105
    ORDER BY d2.div_wins DESC, d2.div_loss ASC, d2.div_rating DESC";
$resdiv = mysqli_query($link, $sqldiv);
$div = array();
while ($rowdiv = mysqli_fetch_array($resdiv)) {
    $div[] = $rowdiv[0];
}
echo var_dump($div[0]);

If I use this SELECT QUERY it works:

$sqldiv = "Select p1.display_name FROM wp_players p1
    JOIN wp_divisions2 d2 ON p1.id = d2.div_player1_id
    JOIN wp_leagues lg ON d2.div_league_ID = lg.league_id
    WHERE d2.player_div_id = 2105
    ORDER BY d2.div_wins DESC, d2.div_loss ASC, d2.div_rating DESC";
$resdiv = mysqli_query($link, $sqldiv);
$div = array();
while ($rowdiv = mysqli_fetch_array($resdiv)) {
    $div[] = $rowdiv[0];
}
echo var_dump($div[0]);

The only difference is that I am using concat. If I run the SELECT Query through SQL I get the output in a single string, which I assume is correct to set $div as an array.

What am I doing wrong?

0

There are 0 best solutions below