我试图在PHP中动态显示选择选项的值。基本上用户创建存储在数据库中的那些选项,然后我试图在不同的地方获取它。为此我编写了以下函数:
function fetch_acad_yr($conn) {
$query = "SELECT a.fk_acadyear_id as acadyearid,b.acad_year as acadyear FROM tbl_admparam a inner join list_acad_years b on a.fk_acadyear_id = b.pk_acad_year_id";
$stmt = $conn->prepare($query);
if ($stmt->execute()) {
foreach ($stmt as $row) {
?>
<option value="<?php echo $row['acadyearid'] ?>"><?php echo $row['acadyear'] ?></option>
<?php
}
}
}
然后在html中我调用了这个函数
<select class="form-control" id="acad_period" name="acad_period" required>
<option value="">Please select...</option>
<?php fetch_acad_yr($conn); ?>
</select>
但是选项会显示任何值,它只是空白而不是显示存储在数据库中的值。我尝试单独运行查询,查询返回所需的结果
答案 0 :(得分:1)
XpsDocument xpsDocument = new XpsDocument(@"C:\pathRoot\fileName.xps", FileAccess.ReadWrite);
XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
xpsDocumentWriter.Write(@"C:\pathRoot\fileName.png");
答案 1 :(得分:0)
确保您拥有正确的连接以及查询结果中的数据。 我使用的基本php mysql代码是下面的,它的工作原理。您将其更改为pdo或推进并获得结果。但是使用与while或for循环相同。
$conn = mysql_connect($host, $username, $pass);
mysql_select_db($dbname, $conn);
echo "<pre>";
echo "<select>";
fetch_acad_yr($conn);
echo "<\select>";
function fetch_acad_yr($conn) {
$query = "SELECT a.fk_acadyear_id as acadyearid,b.acad_year as acadyear FROM tbl_admparam a inner join list_acad_years b on a.fk_acadyear_id = b.pk_acad_year_id";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res)){
?>
<option value="<?php echo $row['acadyearid'] ?>"><?php echo $row['acadyear'] ?></option>
<?php
}
}
?>
适合我。