PHP For loop with differents IDs

Hello people, everything all right ??

I am with the following doubt, hope you can help me !!

In my “mysql” database I have a list with ID = 1, 3 and 4 and I would like to list them in

“html” !!

I can´t list them like:

$sql_list = "SELECT * FROM dados_socios WHERE usuario = '$usuario' ORDER BY ID";
$result_list = $conn->query($sql_list);
	echo "<select>";
	for($x = 0; $x <= $result_list->num_rows; $x++) {
	echo "<option>ID: $x</option>";
	}
	echo "</select>";

Because if I list this way would show:
ID: 1
ID: 2
ID: 3

And I would like the original:
ID: 1
ID: 3
ID: 4

How Can I do that ??
Waiting answer and thanks for the attention !!
One hug

Try this (assuming you’re using MySQLi, it isn’t quite clear from your snippet):

$sql_list = "SELECT * FROM dados_socios WHERE usuario = '$usuario' ORDER BY ID";
$result_list = $conn->query($sql_list);
echo "<select>";
while ($option = $result_list->fetch_assoc()) {
    echo "<option>ID: {$option['ID']}</option>";
}
echo "</select>";

a PDOStatement does not have a property num_rows, so it must be a mysqli_result.

… or something custom :slightly_smiling_face: