代码之家  ›  专栏  ›  技术社区  ›  John

PHP If语句问题

php
  •  1
  • John  · 技术社区  · 17 年前

    $result = mysql_query("SHOW TABLES FROM feather") 
    or die(mysql_error()); 
    
    while(list($table)= mysql_fetch_row($result))
    {
      $sqlA = "SELECT COUNT(*) FROM `$table` WHERE `site` LIKE '$entry'";
    
      $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
      list($isThere) = mysql_fetch_row($resA);
      $isThere = intval($isThere);
      if ($isThere)
      {
         $table_list[] = $table;
      }
    
    }
    
    if(mysql_num_rows($resA)>0){
    foreach ($table_list as $table) { 
        $sql = "SELECT votes_up FROM `$table` WHERE `site` LIKE '$entry'"; 
        $sql1 = mysql_query($sql) or die("$sql:".mysql_error());
       while ($row = mysql_fetch_assoc($sql1)) {
           $votes[$table] = $row['votes_up'];
           $sum += $row['votes_up'];
       } 
    
    }
    }
    else{
    print "";
    }
    
    2 回复  |  直到 17 年前
        1
  •  7
  •   Blixt    17 年前

    $table_list = array(); // <-- Initialize variable.
    while (list($table) = mysql_fetch_row($result)) {
        /* ... */
        $table_list[] = $table;
        /* ... */
    }
    
    if (mysql_num_rows($resA) > 0) {
        foreach ($table_list as $table) { 
            /* ... */
        }
    }
    

    $table_list foreach 循环。首先初始化它以避免这种混淆。

    未添加条目的原因 $table_list 这是因为获取的所有表的计数为零。

        2
  •  0
  •   Christwo    17 年前

    if (is_array($table_list))
    foreach ($table_list as $table) {
      ...
    }
    

    推荐文章