I'm currently new to php and learning but after doing a bit of test, I know that while can't be used twice but I'm not sure how to exactly reset it.
I see that in some scenarios people use reset($variable) but that doesn't seem to work in my case.
In case if it matters, I'm trying to use mysqli to retrieve back my dropdown menu as a selection, the first one works, but the second one doesn't works at all.
<?php
echo '<select>';
while(list($stateID, $stateName) = $result->fetch_row())
{
echo '<option value="$stateName">';
echo "$stateName";
echo '</option>';
}
echo '</select>';
?>
<br>
<br>
To:
<?php
echo '<select>';
while(list($stateID, $stateName) = $result2->fetch_row())
{
echo '<option value="$stateName">';
echo "$stateName";
echo '</option>';
}
echo '</select>';
?>
additionally, in case if it's needed, here's my results on searching in mysql.
<?php
include 'connect.php';
$query = "SELECT * FROM LOCATION";
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
$result2 = $mysqli->query($query, MYSQLI_STORE_RESULT);
if(!$result) {
echo($mysqli->error);
exit();
}
?>
While this method works where I created 2 variables with results 1 and 2, but I have a feeling this isn't the right way to go, especially in the event if I need to reuse the same code over and over again.