Html许多(~30)复选框,如
<input name="heated_seats" value="1" id="heated_seats" type="checkbox">
<input name="electric_windows" value="1" id="electric_windows" type="checkbox">
<input name="cruise_control" value="1" id="cruise_control" type="checkbox">
用户可以检查其中任何一个(可以全部检查,可以不检查任何内容)。
考虑表现。哪个选项更快,使用更少的资源?
选项1
MySQL的
HeatedSeats | ElectricWindows | CruiseControl
----------------------------------------------
1 | 1 | 0
1 | 0 | 0
0 | 0 | 0
查询SELECT HeatedSeats, ElectricWindows, CruiseControl .....
Php赞if( HeatedSeats == 1 ){ echo 'HeatedSeats'; }
许多if
选项2
MySQL的
OneColumnWithPossiblyLongVarcharOrText
----------------------------------------------
Heated seats, Electric windows, ''
Heated seats, '', ''
'', '', ''
查询SELECT OneColumnWithPossiblyLongVarcharOrText .....
Php like
$arr = explode( ',' OneColumnWithPossiblyLongVarcharOrText )
foreach( $arr as $k => $v ){
if( strlen($v) > 0 ){ echo $v; }
}
例如,许多访问者在不同的行上进行相同的选择。
哪个选项花费的时间更少,资源消耗更少?
或者可能有更好的选择?
答案 0 :(得分:1)
选项1对您的方案会更好,如果许多访问者在不同的行上执行相同的选择,则会花费更少的时间。
使用选项1
You have to query and check for multiple conditions which is not good but will help you in future.
On insert you have to insert multiple checkbox value to multipel columns.
使用选项2
You have to query and with some exploding and looping you can easily check which option is checked.
On insert you need to just insert single column value.
But on update it is hard to maintain delimeter values