简体   繁体   English

一个比改变mysql值更好的方法<select>

[英]A better way to change mysql values than <select>

I have made a select code to update my database with: 我已经选择了一个代码来更新我的数据库:

<form method="post" action="<?php $_PHP_SELF ?>">
<table><tr><td style="border:1px solid #000;">
<select name="priv" id="priv">
<option value="<?php echo $pinDetails->is_private; ?>">(<?php echo $pinDetails->is_private; ?>)</option>
<option value="1">Private (1)</option>
<option value="0">Public (0)</option>
</select>
<input name="private" type="submit" id="private" value="Private">
</td></tr></table>
</form>

This basically allows me to change a post from public to private by selecting the appropriate option in the list. 这基本上使我可以通过在列表中选择适当的选项来将帖子从公开更改为私有。 It displays the current value as the first option. 它显示当前值作为第一个选项。

However, this code looks messy and I know the function could probably to achieved a way better way than clicking an option, something along the lines of a button which I can switch on or off like a switch? 但是,这段代码看起来很凌乱,我知道该功能可能比单击一个选项可以实现更好的方式,就像我可以像开关一样打开或关闭按钮的内容?

What would I need to search for or what type of code would work for this? 我需要搜索什么,或者哪种类型的代码适用于此? I'm more than willing to write the code myself given a point in the right direction. 我非常愿意自己编写正确方向的代码。

You can use whatever you want, ie often programmers use radio buttons and style them like a switch. 您可以使用任何您想使用的东西,即程序员经常使用单选按钮并将其样式设置为开关。

Maybe this could be of interest: http://proto.io/freebies/onoff/ 也许这很有趣: http : //proto.io/freebies/onoff/

Also check this jsFiddle : 还要检查此jsFiddle

<div>
    <input type="checkbox" id="switch1" name="switch1" class="switch" />
    <label for="switch1">First switch</label>
</div>
<div class="clear">&nbsp;</div>
<div>
    <input type="checkbox" id="switch2" name="switch2" class="switch" />
    <label for="switch2">Second switch</label>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM