0

I have a drop down that is being populated from a static select. Then when a choice is made in the first drop down a query runs and the second drop down is populated from the database depending on selection in first select box. Here is the code. I'm having a problem displaying the second drop down with the data.

$selectvalue = mysqli_real_escape_string($mysqli, $_GET['selectvalue']);

$result = mysqli_query($mysqli, "SELECT DISTINCT '$selectvalue' FROM accounts ");

echo '<option value="">Please select...</option>';
while($row = mysqli_fetch_array($result))
{
echo '<option value="'.$row['$selectvalue'].'">' . $row['$selectvalue'] . "</option>";
//echo $row['drink_type'] ."<br/>";
 }

 mysqli_free_result($result);
 mysqli_close($connection);

 ?>    
3
  • 1
    select distict 'foo' is selecting the string foo from your table, you're not fetching a field. field/table names can NOT be quoted with '. you have to use backticks: select `foo` from Commented Dec 16, 2014 at 16:32
  • is this the second select box? You are changing depending on first select box...don't you using ajax? Commented Dec 16, 2014 at 16:56
  • Yes, this is the second select box and I'm using ajax to send variable from first drop down. Commented Dec 16, 2014 at 17:12

1 Answer 1

1
<?php
$selectvalue = mysqli_real_escape_string($mysqli, $_GET['selectvalue']);
$result = mysqli_query($mysqli, "SELECT DISTINCT * FROM accounts WHERE col_name = '".$selectvalue."' ");
echo '
<select name="some_name">
<option value="">Please select...</option>';
while($row = mysqli_fetch_array($result)) {
    echo '<option value="'.$row['col_name'].'">'.$row['col_name']."</option>";
}
mysqli_free_result($result);
mysqli_close($connection);
?>
Sign up to request clarification or add additional context in comments.

Comments

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.