通过MySQL使用函数检索数据并在选择框中使用? [英] Retrieving data through mysql using function and use in the select box?

查看:50
本文介绍了通过MySQL使用函数检索数据并在选择框中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序来使用功能通过MySQL检索数据,现在我有一个问题,如何在选择框中使用它?

i write a program to retrieve the data through MySQL using function now i have a problem that how i use it in the select box?

下面给出了此代码,

function selectdata(){
$select="SELECT * FROM table_name";

$run=mysql_query($select);

while($fetch=mysql_fetch_array($run)){
 $field_name.=$fetch['field_name'];


}
return $field_name;
}

HTML:

<select name="office_name">

<option value=""><?php echo selectdata(); ?></option>

</select>

它在一个字段中显示所有数据

it is showing all the data in one field

有帮助吗?

推荐答案

这样做

function selectdata(){
   $select="SELECT * FROM table_name";

   $run=mysql_query($select);
   $field_name = '';
   while($fetch=mysql_fetch_array($run)){
       $field_name.="<option value=''>" . $fetch['field_name'] . "</option>";
   }
   return $field_name;
}

以html

<select name="office_name">
<?php echo selectdata(); ?>
</select>

这篇关于通过MySQL使用函数检索数据并在选择框中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆