<\/script>')

Two tables side by side in function

I have this function to create a table with data from my database.

echo "<table border='1' cellspacing='2' style=\"margin: 20px 0px 20px 20px\">";

for($i = 0; $i<$aantalspelers; $i++){
    $querynaam = "SELECT voornaam FROM team WHERE id=$i" or die(mysql_error());
    $querytussenvoegsel = "SELECT tussenvoegsel FROM team WHERE id=$i" or die(mysql_error());
    $queryachternaam = "SELECT achternaam FROM team WHERE id=$i" or die(mysql_error());
    $querypositie = "SELECT positienaam FROM positie WHERE id=(SELECT positie FROM team WHERE id=$i)" or die(mysql_error());
    $naam = $db->query($querynaam);
    $naam = $naam->fetch();
    $naam_string = $naam['voornaam'];
    $tussenvoegsel = $db->query($querytussenvoegsel);
    $tussenvoegsel = $tussenvoegsel->fetch();
    $tussenvoegsel_string = $tussenvoegsel['tussenvoegsel'];
    $achternaam= $db->query($queryachternaam);
    $achternaam = $achternaam->fetch();
    $achternaam_string = $achternaam['achternaam'];
    $positie = $db->query($querypositie);
    $positie = $positie->fetch();
    $positie_string = $positie['positienaam'];

    $inserttable = "<th rowspan='3'><img src=\"images/spelers/$i.jpg\" width='85' height='130'/></th>"
        .'<tr><th>Voornaam</th><th>Tussenvoegsel</th><th>Achternaam</th><th>Positie</th></tr>'
        .'<tr><td>'.$naam_string.'</td><td>'.$tussenvoegsel_string.'</td><td>'.$achternaam_string.'</td><td>'.$positie_string.'</td></tr>';

    echo $inserttable;
}

echo "</table>";

Now this works fine and that’s it, but I would like to have as 2 rows in my table:

[id 0 info] | [id 1 info]
[id 2 info] | [id 3 info]

but now my table is similar:

[id 0 info]
[id 1 info]
[id 2 info]

How can I make them look like 2 tables side by side?

Thank.

EDIT: clearer: I have it so; now , but I want it to be so; want to

+4
source share
1 answer

Use an array index in conjunction with a module to stack rows next to each other.

Something like that:

for($i = 0; $i<$aantalspelers; $i += 2){
        $table1_rows .="<tr><td>$aantalspelers[i]["id"]</td></tr>";
        $table2_rows .="<tr><td>$aantalspelers[i+1]["id"]</td></tr>";
}

css, :

$table_head = "<table><tr><th>whatever headings</th></tr>";
$table_foot = "</table>";
$table1 = $table_head.$table1_rows.$table_foot;
$table2 = $table_head.$table2_rows.$table_foot;
+1

Source: https://habr.com/ru/post/1535097/


All Articles