Multidimensional array to html-table

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Aug 07, 2018 12:59 pm

Tue Aug 07, 2018 1:14 pm

I have this code where I try to print out some users predictions for 48 games to a html table. It does what I wan't but some weird characters is coming up when the two foreach loops runs. The code can be viewed here.

The weird characters is the line that looks like this - - - - - - 0-6 - n-i a-n d a-n d a-r a a-r a - - - - - - n-i

Where does this come from? I have a print_r added to the code so you can see how the array is build.

Code: Select all

include 'conn2.php';

$conn->query("SET lc_time_names = 'sv_SE'") or die($conn->error());

$matcher = mysqli_query($conn, "SELECT * ,DATE_FORMAT( gamedate,  '%d %M'  )  AS gamedate FROM matcher LIMIT 0 , 48");

$sql = "SELECT A.namn, enamn, B.*
            FROM userdata A
            LEFT OUTER JOIN matchtips B ON ( A.user_id = B.user_id )
            WHERE paid = '1'
            GROUP BY   matchid,enamn,namn";
$predictions = $conn->query($sql);

while ($row = mysqli_fetch_array($matcher))
$rows[$row['game_id']] = $row;

while ($row=mysqli_fetch_array($predictions))
       $rows[$row['matchid']][] = $row;

echo "<table class='kantlinje' bgcolor='#F9F9F9' border='0' cellpadding='4' cellspacing='3'>\n";
    foreach ($rows as $game_id => $row)
                echo "<tr>";
                echo "<td>$row[game_id] $row[grupp] $row[gamedate] $row[hometeam]-$row[awayteam] $row[homegoal]-$row[awaygoal] $row[sign]</td>";
                foreach($row as $row)
                    echo "<td>$row[5]-$row[6] $row[7]</td>";
                echo "</tr>";
echo "</table>";


User avatar
New php-forum User
New php-forum User
Posts: 55
Joined: Mon Oct 16, 2017 1:06 pm

Wed Aug 08, 2018 8:50 am

I dont see what you are talking about.

That is some pretty bad code by the way. Best thing to do is post an SQL dump of your schema along with a few sample records and then tell us what you want to know from the data.
The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

Post Reply