【问题标题】:I can't seem to get the IF condition I'm looking for我似乎无法获得我正在寻找的 IF 条件
【发布时间】:2017-07-11 06:56:16
【问题描述】:

我的功能正常工作,我似乎无法获得正确的 IF 条件来包装它。我想要实现的只是在 WHILE 有任何要显示的内容时创建链接列表。

所以如果我在线程 id 3 上并且它有 2 个插件线程 id 4,5 它将创建:

<ul>
  <li><a href="showthread.php?t=4">Link 4</a></li>
  <li><a href="showthread.php?t=5">Link 5</a></li>
</ul>

如果我在线程 2 上并且它没有插件线程 ID,它应该什么也不返回。

这是我目前没有条件的。

$addonid = $db->query_read ("
  SELECT drc.threadid AS threadid
  FROM `" . TABLE_PREFIX . "modsys_settings` AS drc
  LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread
  ON(drc.mod_addons=" . $threadinfo['threadid'] . ")
  WHERE thread.threadid IN (" . $threadinfo['threadid'] . ")
");
  $post['addons'] = '<ul>';

  while ($addons = $db->fetch_array ($addonid)) {    
    $ci_counter = $db->query_read ("
      SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle
      FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
      LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
      WHERE thread.threadid IN (" . $addons['threadid'] . ")
    ");

    $counter = $db->fetch_array ($ci_counter);
    $post['addons'] .= '<li><a href="showthread.php?t=' .   $addons['threadid'] . '">'. $counter['threadtitle'] .'</a></li>';
  }

  $post['addons'] .= '</ul>';

【问题讨论】:

    标签: mysql if-statement while-loop conditional-statements vbulletin


    【解决方案1】:

    你能做类似$addonid-&gt;num_rows 的事情吗?

    $show_list = $addonid->num_rows;
    if($show_list)
         $post['addons'] = '<ul>';
    

    然后过了一会儿

    if($show_list)
        $post['addons'] = '</ul>';
    

    【讨论】:

    • @JuanCarlosOropeza 谢谢!
    • 我尝试使用 $show_list = $addonid->num_rows; if($show_list){ $post['addons'] = '
        '; } 并且它实际上根本没有显示
          =/(不能让 ctrl k 工作哈哈)
    • 我不得不为我正在开发的软件调整它,但我明白了 =) $show_list = $db->num_rows ($addonid)
    【解决方案2】:

    我不怎么玩php,所以我会给你一些一般的指导。

    只需使用一个布尔变量来控制何时创建和关闭它。

     @i_create_a_tag = false;
    
     while ( something ) {
         -- open the tag only once
         if (!@i_create_a_tag) {
             $post['addons'] = '<ul>';
             @i_create_a_tag = true;
         }
    
         ....          
     }
    
     -- close the tag if was open
     if (@i_create_a_tag) {
        $post['addons'] = '</ul>';
     }
    

    【讨论】:

    • 我也试过这个并且@给了我“语法错误,意外'='”所以我用$替换了,仍然没有
      猜你喜欢
      • 1970-01-01
      • 2023-03-14
      • 2013-11-23
      • 2011-07-19
      • 2017-09-20
      • 2015-10-05
      • 2019-11-21
      • 2014-03-28
      • 2017-09-19
      相关资源
      最近更新 更多