I have to fetch country name twice in the single page. I have four dropdowns which is country_1,state_1, country_2, state_2.
In the country, User select the country name and according to the country name, state name will display. If I use only country_1, state_1 then I am able to display it but I need both countries dropdown on the same page.
I tried $stmt->data_seek($stmt,0);
$stmt->data_seek(0);
but still not able to display it.
I just want to know where should I use the data_seek
<!--country name-->
$country_list="SELECT id,name FROM countries";
/* create a prepared statement */
if ($stmt = $conn->prepare($country_list)) {
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($id, $country_name);
}
<select name="country_data" class="myselect form-control country_data">
<option value="" disabled selected>Select your country</option>
<?php while ($stmt->fetch()) {?>
<option value="<?php echo $id;?>"><?php echo $country_name;?></option>
<?php }?>
</select>
<!--state name-->
<select name="state" class="myselect form-control state_get" >
<option value=''>Select state</option>
</select>
<!--country name-->
<select name="country_data" class="myselect form-control country_data">
<option value="" disabled selected>Select your country</option>
<?php
$stmt->data_seek($stmt,0);
while ($stmt->fetch()) {?>
<option value="<?php echo $id;?>"><?php echo $country_name;?></option>
<?php }?>
</select>
<!--state name-->
<select name="state" class="myselect form-control state_get" >
<option value=''>Select state</option>
</select>