I have a big problem. I get data from a database. I want to display them in tabs. My method is a loop in a loop. I show you the code. My problem is that the result (second loop) all data are output.
The first loop displays each user name with the same id, in a own tab. that works. the second loop operates on the same principle. but the second loop does not filter.
(!) The first loop show me correctly for every username with the same id the own Tab. but the sec on loop show me all event_names, not only the event names of the users. Resume: i got 3 user. every user. user 1 has his own tab. (2 events) user 2 has his own tab. (1 event) user 3 has his own tab. (1 event) in the second loop, i ask the events of every user. in the tab of user 1 must appear 2 events in the tab of user 2 must appear 1 event and in the tab of user 3 must appear 1 event too. BUT, in every tab (user 1,2 and 3) appear 4 events. the events of all users... is it a problem with the loop, isn't it? (!)
Can someone help me?
Here some pictures of the table and output:
My table users

the code:
<?php
$db = mysqli_connect(DB_HOST, DB_BENUTZER, DB_password, DB_NAME);
mysqli_set_charset($db, "utf8");
$sqli2 = "SELECT username, premium FROM users WHERE id = $id ";
$result2 = mysqli_query($db, $sqli2);
foreach ($result2 as $row2)
{
echo '<div class="tabs">';
My table party:

the code:
$db = mysqli_connect(DB_HOST, DB_BENUTZER, DB_password, DB_NAME);
mysqli_set_charset($db, "utf8");
$sqli = "SELECT party_id, event_name, beginn, ende, unternehmen FROM party WHERE unternehmen = '".$row2['username']."' ";
$result = mysqli_query($db, $sqli);
while ($row = mysqli_fetch_assoc($result))
{
echo '<h3> '. $row['unternehmen'] .' '. $row['event_name'] .' </h3>';
and my output:

Where is the error? I can't believe it :-( Please help me!!!!
here the full code:
<?php
$db = mysqli_connect(DB_HOST, DB_BENUTZER, DB_password, DB_NAME);
mysqli_set_charset($db, "utf8");
$sqli2 = "SELECT username, premium FROM users WHERE id = $id ";
$result2 = mysqli_query($db, $sqli2);
foreach ($result2 as $row2) {
echo '<div class="tabs">';
echo '<ul>';
echo '<li><a href="#tabs-1"> '. $row2['username'] .' </a></li>';
echo '<li><a href="#tabs-2">Proin dolor</a></li>';
echo '<li><a href="#tabs-3">Aenean lacinia</a></li>';
echo '</ul>';
echo '<div id="tabs-1">';
echo '<p>Proin elit ac sollicitudin mi sit amet mauris. Nam elementum quam us.</p>';
echo '</div>';
echo '<div id="tabs-2">';
echo '<p><div class="accordion">';
$db = mysqli_connect(DB_HOST, DB_BENUTZER, DB_password, DB_NAME);
mysqli_set_charset($db, "utf8");
$sqli = "SELECT party_id, event_name, beginn, ende, unternehmen FROM party WHERE unternehmen = '".$row2['username']."' ";
$result = mysqli_query($db, $sqli);
while ($row = mysqli_fetch_assoc($result))
{
echo '<h3> '. $row['unternehmen'] .' '. $row['event_name'] .' </h3>';
echo '<div> ';
echo '<form enctype="multipart/form-data" method="post" >';
echo '<legend>Event Daten</legend>';
echo '<label for="event_name">Name:</label>';
echo '<input type="text" id="event_name" name="event_name" value="'. $row['event_name'] .'" /><br />';
echo '<label for="beginn">Beginn:</label>';
echo '<input type="text" id="beginn" name="beginn" value=" '. $row['beginn'] .'" /><br />';
echo '<label for="party_id" value=" '. $row['party_id'].'"> Party ID:'. $row['party_id'].' </label>';
echo '<input type="radio" id="party_id" name="party_id" value=" '. $row['party_id'] .'" /><br />';
echo '</fieldset>';
echo '<input type="submit" value="Änderungen speichern" name="partyspeicher" />';
echo '</form>';
echo '</div>';
}
echo '</div>';
echo '</p>';
echo '</div>';
echo '<div id="tabs-3">';
echo '<p> Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>';
echo '</div>';
echo '</div>';
}
?>