dpd20130 2014-12-28 04:35
浏览 49
已采纳

Mysql SELECT多列或一列,然后用php显示结果。 哪个选项更适合性能

Html many (~30) check-boxes like

<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">

User may check any of them (may check all, may check nothing).

Thinking about performance. Which option would be faster and use less resources?

Option 1

mysql

HeatedSeats | ElectricWindows | CruiseControl
----------------------------------------------
   1        |     1           |   0
   1        |     0           |   0
   0        |     0           |   0

Query like SELECT HeatedSeats, ElectricWindows, CruiseControl .....

Php like if( HeatedSeats == 1 ){ echo 'HeatedSeats'; } Many if

Option 2

mysql

OneColumnWithPossiblyLongVarcharOrText
----------------------------------------------
Heated seats, Electric windows, ''
Heated seats, '', ''
'', '', ''

Query like SELECT OneColumnWithPossiblyLongVarcharOrText .....

Php like

 $arr = explode( ',' OneColumnWithPossiblyLongVarcharOrText )
 foreach( $arr as $k => $v ){
 if( strlen($v) > 0 ){ echo $v; }
 }

For example many visitors do the same select on different rows.

Which option takes less time and uses less resources?

Or may be there some better option?

  • 写回答

1条回答 默认 最新

  • dongpu1315 2014-12-28 04:55
    关注

    Option 1 will be better for your scenario and it will take less time if many visitors do the same select on different rows.

    With Option 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.
    

    With Option 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败