du1462 2016-04-03 13:27
浏览 41

PHP MySQL ORDER BY无法正常工作

I have a query:

$team_member_result = mysql_query("SELECT * FROM teams 
             WHERE team_creator LIKE '%,$player_main_id,%' 
               OR team_owner LIKE '%,$player_main_id,%' 
               OR team_leaders LIKE '%,$player_main_id,%' 
               OR team_captains LIKE '%,$player_main_id,%' 
               OR team_members LIKE '%,$player_main_id,%' 
             ORDER BY team_creator ASC, team_owner ASC, 
                      team_leaders ASC, team_captains ASC, 
                      team_members ASC");

It works at the start, but if the member is not a creator it starts to sort unordered, so basically if they are a member it will show before they are a leader.

Not sure what to do,

Thanks!

  • 写回答

1条回答 默认 最新

  • douye6812 2016-04-03 17:19
    关注

    The main problem is that your tables are not in the Third normal form. Because of that you try to develop an SQL query which ultimately doesn't work, specially the ORDER BY part (besides the already mentioned LIKE filter with commas).

    Bring your tables in the 3NF, then you can write an ORDER BY statement which makes sense.

    Btw.: Don't use the mysql_*() functions anymore, they are deprecated. Use PDO instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)