简体   繁体   English

如何从数据库mysql以表格形式选择html获取数据?

[英]how to get data from database mysql in form select html?

i was trying to show data from database into tag> select html. 我试图将数据从数据库显示到标签中>选择html。 here is the code : 这是代码:

<?php
require 'koneksi.php';
$sql_select = "SELECT nama_supplier FROM supplier"; 
$hasil = mysql_query($sql_select);
  if(!$hasil) {
  echo "data not found ".mysql_error();
  }
  mysql_close();
?>
<div class="par control-group">
    <label class="control-label" for="supplier">Supplier</label>
    <select name="supplier" class="uniformselect">
    <?php
       while($baris = mysql_fetch_array($hasil)){
       echo "<option value='$baris'>".$baris."</option>";           
       }
    ?>
    </select>
</div>

the problem is, the output doesn't show the option value from database. 问题是,输出未显示数据库中的选项值。 the output only print 'array'. 输出仅打印“数组”。 here is screenshot : image . 这是屏幕截图: 图片 i know that it has to be something simple that i am missing but seriously i cannot figure it out. 我知道这很简单,我很想念,但严重的是我无法弄清楚。 please anyone help, thanks! 请任何人帮助,谢谢!

You need to select a row from the $baris variable which stands as an array 您需要从$ baris变量中选择一个代表数组的行

echo $baris['Coulmn you want'];

If you don't the variable $baris will be equal to something like that. 如果不这样做,变量$ baris将等于这样。 You need to select which column you want. 您需要选择所需的列。

([id]->1,[name]->'user',...,['email']->a@a.com)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM