catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

does medoo not support view data with ajax #1043

Closed nahrunhartono closed 2 years ago

nahrunhartono commented 2 years ago

Ajax :

<script type="text/javascript">
    $(document).ready(function(){
      $.ajax({
       type: 'POST',
       url: "template/module/objek/get_provinsi.php",
       cache: false,
       success: function(msg){
      $("#provinsi").html(msg);
    }
});
</script>

Select Form :

<div class="form-group">
  <label>Letak</label>
    <div class="row">
     <div class="col-sm-6">
      <select class="form-control" name="provinsi" id="provinsi">
              <option value=""> ---Pilih Provinsi</option>
          </select>
     </div>
   </div>
</div>  

get_provinsi.php (location file: template/module/objek) :

<?php
  $query=$database->select('wk_provinsi','*');
  foreach ($query as $query) {
    echo "<option value=''>Pilih Provinsi - - </option>";
  }
?>

data does not appear on the select form does medoo not support view data with ajax ??

catfan commented 2 years ago

Check out this error code:

  foreach ($query as $query) {
    echo "<option value=''>Pilih Provinsi - - </option>";
  }
nahrunhartono commented 2 years ago

`<?php

echo "";

$query=$database->select('wk_provinsi','*'); foreach ($query as $query) { // echo ""; echo "<option value='" . $query['id_provinsi'] . "'>" . $query['provinsi'] . ""; }

?> `

Not work bro

catfan commented 2 years ago
foreach ($query as $query)

Cannot write like this.

Please read the PHP documentaion on how to write the correct foreach expression. https://www.php.net/manual/en/control-structures.foreach.php