doudengjin8251 2013-08-06 17:29
浏览 35

多次重复相同的长码

I'm doing a workaround to filter results using Cimy User Extra fields (I'm not able to do queries and so). So I created a dropdown form and I'm using the selected fields/values to filter the users to be shown.

Here is the function of the Wordpress Users plugin used to display de users "list"

function get_user_listing($curauth) { 
  global $post;
  $concat = wpu_concat_single();
  $homeuni=get_cimyFieldValue($curauth->ID,'homeuni');
  $selectedhomeuni = $_GET['homeunis']; // Key that gets one dropdown value
  $selectedhostuni = $_GET['hostunis']; // Key that gets the other dropdown value

if($selectedhomeuni == "all" && $selectedhostuni == "all") {
// Here goes the bunch of repeated code
 }
elseif($selectedhomeuni != "all" && $selectedhostuni == "all") {
// Here goes the bunch of repeated code again
 }
elseif($selectedhomeuni == "all" && $selectedhostuni != "all") {
 // Here goes the bunch of repeated code again
}  
elseif($selectedhomeuni != "all" && $selectedhostuni != "all") {
 // Here goes the bunch of repeated code again
}

  return $html;
}

And here (Pastebin) is the long code to be repeated. with ", ', \" and $.

I've tried functions, keys and include to call that code, but none of them worked properly. I'm not even sure it can be done this "easy" as I'm trying. I'm no expert at all.

Thank you very much.

  • 写回答

1条回答 默认 最新

  • duanjiaolao1187 2013-08-08 10:45
    关注

    I just had to put the "return $html;" inside the {} (where I wrote the "here goes..." and that was it!

    Now I just have to find a better way to set the possible combinations (I have to add 2 more options, which leaves me with 16 possibilities...)

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100