0

I want to display a drop-down list which pull out database values. My actual code working fine, but here I have to provide the list in the array itself. What i required is, without editing the code, i needed to pull out values from database to this array("state1","state2"....); which is equal to something like this array("$states");

$sql = "SELECT * FROM `States`";
$result = $conn->query($sql);
$i=0;
while($row = $result->fetch_assoc()) {  
  $t=$row['statename'];
  $t[$i]=$row['statenname'];
  $i++;
}
$countryArr = array( "INDIA" => array("$t"));

I tried the above code but its listing only one value from database.

1 Answer 1

1

Remove this line

$t=$row['statename'];

just keep it to be

$t[$i]=$row['statenname'];

Sign up to request clarification or add additional context in comments.

3 Comments

i did that, but here also one value shows in option list, i think the while loop end value is shown in array. that is the reason it shows the last value aas option. is there any way to get values inside array like this : array("$t[1]","$t[2]","$t[3]"));
Why are you doing $countryArr = array( "INDIA" => array("$t")); and not $countryArr = array( "INDIA" => $t));
Add the expected output array to your question, that will help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.