I have two tables: categories and models. For now, categories table is important.
| id | nazwa | desc_s1 | photo | active | id_user |
| 1 | Audi | test | url | 1 | 2 |
| 2 | BMW | test | url | 1 | 2 |
| 3 | Ford | test | url | 1 | 2 |
| 4 | BMW | test | url | 1 | 2 |
And I have php:
$query_categories = "SELECT * FROM `categories` WHERE nazwa='$selected_category' AND active=1 AND id_user=".$_SESSION['id_user'].";";
$query_model = "SELECT * FROM models WHERE active=1";
$result_categories = mysqli_query($con, $query_categories);
$result_model = mysqli_query($con, $query_model);
if (mysqli_num_rows($result_categories) > 0 && mysqli_num_rows($result_model) > 0) {
$row_categories = mysqli_fetch_assoc($result_categories);
$selected_category = $row_categories['nazwa'];
$_SESSION['selected_category'] = $selected_category;
$_SESSION['title_content'] = $title_content;
$_SESSION['price'] = $price;
$category = $row_categories['nazwa'];
$desc_s1 = $row_categories['desc_s1'];
$photo = $row_categories['photo'];
$row_model = mysqli_fetch_assoc($result_model);
$selected_model = $row_model['model'];
$stan = $row_model['stan'];
$przeznaczenie = $row_model['przeznaczenie'];
$kolor = $row_model['kolor'];
$typ = $row_model['typ'];
$table = array();
do
{
array_push($table, '
<tr>
<td class="text-left">353</td>
<td class="text-left">Stan|' . $row_model['stan'] . '<br />Przeznaczenie|' . $row_model['przeznaczenie'] . '<br />Kolor|' . $row_model['kolor'] . '<br />Typ|' . $row_model['typ'] . '<br /></td>
<td class="text-left">' . str_replace(' ', '_', $row_model['model']) . '<br /></td>
<td class="text-left">' . $title_content . ' ' . $selected_category . ' ' . $row_model['model'] . '</td>
<td class="text-left">' . $price . '</td>
<td class="text-left">' . nl2br($row_categories['photo']) . '</td>
<td class="text-left">' . nl2br(htmlspecialchars($row_categories['desc_s1'])) . '</td>
</tr>');
} while ($row_model = mysqli_fetch_array($result_model));
} else {
array_push($errors, '<span class="badge badge-warning">Error</span>');
}
Its working but, the output table gives me 3 results, missing is the last one. I know the reason is the same name name like row id=2 but how to get all of the rows in result? I have tried with while inside while but it doesn't work as I thought.