Populate more than one drop down using the same mysql query

前端 未结 3 666
礼貌的吻别
礼貌的吻别 2021-01-25 07:14

I have form with a number of drop boxes which have the numbers 1-5 in them. I can use this code to populate a drop down but was wondering if I can somehow only make the call to

3条回答
  •  有刺的猬
    2021-01-25 07:30

    Simply get the results into an array using the fetch_all method. It returns all rows from the result set into an associative or numeric array. The you can do whatever you want with such array:

    $result = $conn->query('SELECT * FROM riskNumDrop');
    if (!$result) {
       echo "query failed: (" . $mysqli->errno . ") " . $mysqli->error;
       exit; // fetch_* functions cannot be called on error (sice $result is false)
    }
    
    // get all rows from the result
    $rows = $result->fetch_all(MYSQLI_ASSOC);
    
    // output first dropdown...
    echo '';
    
    // output second dropdown...
    echo '';
    

提交回复
热议问题