George Nostradamos George Nostradamos - 4 months ago 8
PHP Question

PHP: MySQL values call based on dropdown

So what Ia m trying to do is to call a value from my server and input it in a variable based on what I have chosen from the dropdown box and then I want to take those variables and calculate a new output through javascript (I don't think that I want help for the last part but I like being up-front).Anyway here is the code

$db_name= 'prod_chrotex_db';
$conn = new mysqli($host, $user, $pass, $db_name);

$query = mysqli_query($conn,"SELECT * FROM table1 INNER JOIN table2 ON id ");

echo '<select name="TITLE">';

while ($row = mysqli_fetch_array($query)) {
echo '<option value="'.$row['title'].'">'.$row['title'].'</option>';
$rows = mysqli_fetch_assoc($query);
echo 'ID: ' . $rows['ID'] ;
$value=$rows['values']
};

echo "</select>";

?>

Answer

I think that is waht you are trying to achieve. HTML selet options should be outside the while loop

$db_name= 'prod_chrotex_db';
    $conn = new mysqli($host, $user, $pass, $db_name);

    $query = mysqli_query($conn,"SELECT * FROM table1 INNER JOIN table2 ON id ");
     while ($row = mysqli_fetch_array($query)) {
      $title = $row["title"];
      $id = $row["ID"];
       $value=$rows['values'];
      }
    echo '<select name="TITLE">';

       echo '<option value="'.$title.'">'.$title.'</option>';
     echo 'ID: ' . $id ;
      echo  $value;

    echo "</select>";