我在php中创建了动态列表。
<select name="student" >
<option selected disable class="hideoption">Student Name</option>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
echo<option value='".$row['path']."'>'".$row['studentName']."'</option>";
}
?>
</select>
当我选择列表时,它会给出空字符串。但是当我没有被选中时,它会返回第一个值Student Name
。我试图从这一行获得价值。
if(isset($_POST['student'])){
$selectedName = $_POST['student'];
}
我还尝试检查isset
是设置还是空。 isset
已设置但为空。
这是Google
提供的唯一解决方案。想法?
修改
我已经解决了这个问题。以下答案的解释。
答案 0 :(得分:1)
起初我认为$_POST['student']
会在<option>
标记内返回文字而我错了。我知道它返回应该在<option>
属性中设置的值,所以我只是将值设置为$row['studentName']
,因为$row['path']
返回空字符串。如果我说错了,请纠正我。所以基本上,代码如下所示。
<select name="student" >
<option selected disable class="hideoption">Student Name</option>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
echo<option value='".$row['studentName']."'>'".$row['studentName']."'</option>";
}
?>
</select>
感谢您的所有回复。你的回答让我想到我应该怎么做。
答案 1 :(得分:0)
使用以下代码:
<select name="student" id="student" >
<option selected disable class="hideoption">Student Name</option>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
echo "<option name='".$row['studentName']."' value='".$row['path']."'>'".$row['studentName']."'</option>";
}?>
</select>
答案 2 :(得分:0)
您应该对选定的AElements @Name='3'
<fo:root>
<fo:block>STEP 1 0000</fo:block>
<fo:table>
<fo:table-row>
<fo:table-cell>
<fo:block>
1000
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
2000
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
3000
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table>
<fo:block>STEP 2 1000</fo:block>
<fo:table>
<fo:table-row>
<fo:table-cell>
<fo:block>
0100
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
0300
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table>
<fo:block>STEP 2 2000</fo:block>
<fo:table>
<fo:table-row>
<fo:table-cell>
<fo:block>
0500
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table>
<fo:block>STEP 2 4000</fo:block>
<fo:table>
<fo:table-row>
<fo:table-cell>
<fo:block>
0600
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table>
<fo:block>STEP 3 0600</fo:block>
<fo:table>
<fo:table-row>
<fo:table-cell>
<fo:block>
0010
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table>
</fo:root>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
>
<xsl:output indent="yes" />
<!-- all <AElement> we consider for output, indexed by their @Name and group ID -->
<xsl:key name="AElementGroup1" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '1'][1]))
" />
<xsl:key name="AElementGroup2" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '2'][1]))
" />
<xsl:key name="AElementGroup3" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '3'][1]))
" />
<xsl:key name="AElementGroup4" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '4'][1]))
" />
<xsl:key name="AElementGroup5" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '5'][1]))
" />
<xsl:key name="AElementGroup6" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '6'][1]))
" />
<xsl:key name="AElementGroup7" match="AElement[AElement/Child1 = 'E']" use="
concat(@Name, '|', generate-id(preceding-sibling::AElement[@Name = '7'][1]))
" />
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master
master-name="DIN-A4-Landscape"
page-height="210mm"
page-width="297mm"
margin-left="1mm"
margin-right="1mm"
margin-top="1mm"
margin-bottom="1mm"
>
<fo:region-body margin="1mm"/>
<fo:region-before region-name="header" extent="5mm"/>
<fo:region-after region-name="footer" extent="15mm"/>
<fo:region-start region-name="left" extent="5mm"/>
<fo:region-end region-name="right" extent="5mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="DIN-A4-Landscape">
<fo:flow flow-name="xsl-region-body">
<xsl:call-template name="ink">
<xsl:with-param name="Now" select="1"/>
</xsl:call-template>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="ink">
<xsl:param name="Now"/>
<xsl:param name="Next" select="$Now + 1"/>
<xsl:param name="Ende" select="3"/>
<xsl:apply-templates select="ROOT">
<xsl:with-param name="nowStep" select="$Now"/>
<xsl:with-param name="nextStep" select="$Next"/>
</xsl:call-template>
<xsl:if test="$Ende > $Now">
<xsl:call-template name="ink">
<xsl:with-param name="Now" select="$Now + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="ROOT">
<xsl:param name="nowStep"/>
<xsl:param name="nextStep"/>
<xsl:for-each select="AElement[@Name = $nowStep]">
<xsl:variable name="groupId" select="generate-id()" />
<xsl:variable name="groupKey" select="concat($nextStep, '|', $groupId)" />
<fo:block><xsl:value-of select="concat('STEP ' , $nowStep)" /></fo:block>
<xsl:variable name="group">
<xsl:value-of select="concat('InternalElementGroup',$nowStep)"/>
</xsl:variable>
<xsl:if test="count(key($group, $groupKey))>=1">
<fo:table page-break-after="always">
<fo:table-body>
<xsl:choose>
<xsl:when test="$nowStep = 1">
<xsl:apply-templates select="key('AElementGroup1', $groupKey)/AElement" />
</xsl:when>
<xsl:when test="$nowStep = 2">
<xsl:apply-templates select="key('AElementGroup2', $groupKey)/AElement" />
</xsl:when>
<xsl:when test="$nowStep = 3">
<xsl:apply-templates select="key('AElementGroup3', $groupKey)/AElement" />
</xsl:when>
</xsl:choose>
</fo:table-body>
</fo:table>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="AElement/AElement">
<fo:table-row>
<fo:table-cell>
<fo:block><xsl:value-of select="Child2"/></fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:transform>
答案 3 :(得分:0)
@dongcheng这是相同的代码,但具有更好的对齐方式。所以你可以清楚地看到你的代码。
<select name="student">
<option selected disable class="hideoption">Student Name</option>
<?php
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
echo '<option value="' . $row['path'] . '">' . $row['studentName'] . '</option>';
}
?>
</select>
使用
$selectedStudent = !empty($_POST['student']) ? $_POST['student'] : '';
if ($selectedStudent) {
// your code
}