This is my code to get name list from the database but I am not able to get values where is the error can anyone pls help me
// database connection where php is my database name
<?php
$con=mysql_connect("localhost","root","root");
mysql_select_db("php",$con);
?>
// html body for getting value in option
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post">
<select name="select" >
<option>Select College From Here</option>
<?php $getoptions = get_name(); ?>
<?php foreach ($getoptions as $key => $value) { ?>
<option><?= $value ?></option>
<?php } ?>
</select>
<input type="submit" name="sub">
</form>
// function to get name list from the database is this query right or wong ??
<?php
function get_name(){
$option=array();
$query="select * From login ";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$option [$row->id] = strtoupper($row->name);
}
$option;
}
?>
帮助我解决这个问题,该函数没有从表中返回我的名称,并且我无法看到选择框中的列表..并告诉我如何查看函数将返回什么如何获取函数返回值, 我可以提醒返回值或回显该值吗
最佳答案
尝试一下但未经测试
function get_name()
{
// your code
while($row=mysql_fetch_array($result)){
$id = $row['id'];
$option [$id] = strtoupper($row['name']);
}
return $option;
}
检查此测试
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
echo $id . "==" . $row['name'];
echo "<br>";
$option [$id] = strtoupper($row['name']);
}
$option;
print_r($option);
关于php - 如何使用php中的函数从数据库获取姓名列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43451915/