PHP 从 MySQL 中选择多个选择选项
我正在尝试从数据库中加载多个选择进行编辑。
我将原始数据存储在一个内爆字符串中(即“4,6,8,9”)。
我想要做的是从数据库中分解该字符串,然后在加载编辑表单时选择值。值是 Float,然后是 1-52。
这是我到目前为止的代码,但它没有选择值。
$listing->getWeeksAvail() 只是一个返回 WeeksAvail 属性的调用,在本例中为“4, 6, 8, 9)
<?php
$weeks_available = explode(",", $listing->getWeeksAvail());
if (in_array("Float", $weeks_available)) {
echo " selected='selected'";
}
?>
>Float</option>
<?php
for($float=0; $float<=52; $float++) {
echo "<option value=\"$float\"";
if (($listing instanceof listing) && $float == $listing->getWeeksAvail()) {
echo " selected='selected'";
}
echo ">$float</option>\n";
}
I am trying to load a mulitple select from the database to edit.
I am storing the original data in an imploded string (ie "4, 6, 8, 9").
What I want to do is explode that string from the database, then have the values selected when the edit form is loaded. The values are Float, then 1-52.
Here is the code I have so far, but it does not select the values.
$listing->getWeeksAvail() is just a call that returns the WeeksAvail property in this case "4, 6, 8, 9)
<?php
$weeks_available = explode(",", $listing->getWeeksAvail());
if (in_array("Float", $weeks_available)) {
echo " selected='selected'";
}
?>
>Float</option>
<?php
for($float=0; $float<=52; $float++) {
echo "<option value=\"$float\"";
if (($listing instanceof listing) && $float == $listing->getWeeksAvail()) {
echo " selected='selected'";
}
echo ">$float</option>\n";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码的第二部分应该是这样的:
The second part of your code should be like this:
你可以尝试
you can try