将选项值从回显部分存储到PHP变量中的问题
$var=$_POST[select_tag_name]
$query="SELECT subject.`SubjectName`
FROM `subject`
LEFT JOIN `class-sub-info` USING(SubjectId)
WHERE `ClassID`=$classid";
$result=mysqli_query($con,$query);
if(mysqli_num_rows($result) > 0)
{
while($row=mysqli_fetch_assoc($result))
{
echo "<option value=".$row["SubjectId"].">".$row["SubjectName"]."</option>";
}
}
期望将值存储到php变量的简单方法
答案 0 :(得分:0)
使用补偿运算符(。)合并输出。
首先创建一个变量,如$ result并分配空值。之后,使用补偿运算符将输出分配给变量。
$var=$_POST[select_tag_name]
//create a variable $result and assign empty value
$subject= '';
$query="SELECT subject.`SubjectName`
FROM `subject`
LEFT JOIN `class-sub-info` USING(SubjectId)
WHERE `ClassID`=$classid";
$result=mysqli_query($con,$query);
if(mysqli_num_rows($result) > 0)
{
while($row=mysqli_fetch_assoc($result))
{
//Use the Compensation Operator(.) to assign the output in variable
$subject.="<option value=".$row["SubjectId"].">".$row["SubjectName"]."</option>";
}
}
//At last display that variable
echo $subject;