错误在哪里?

时间:2014-06-20 08:13:24

标签: php function social

我正在尝试创建社交链接。

我的数据库字段是

----------------------------------------------------------------------------------------------------------------------
| SocialId | SocialName |    ButtonClass              |  SocialIcon   |      SocialUrl    |  SocialShow | SocialSort |
----------------------------------------------------------------------------------------------------------------------
| 1        |  Facebook  | btn btn-social btn-facebook | icon-facebook | #                 |  active     | 1          |
----------------------------------------------------------------------------------------------------------------------
| 2        |  Twitter   | btn btn-social btn-twitter  | icon-twitter  | #                 |  active     | 2          |
----------------------------------------------------------------------------------------------------------------------

为此,我编码如下:

// Social Links ---------------------------------------------------
mysql_select_db($db,$con);
$qry5 = "SELECT * FROM social ORDER BY SocialSort ASC";
$clt_soc = mysql_query($qry5,$con);
$clt_social = mysql_fetch_assoc($clt_soc);

function cltsocial(){
    global $clt_social;
    $soc_show = $clt_social('SocialShow');
    $soc_class = $clt_social('SocialClass');
    $soc_url = $clt_social('SocialUrl');
    $soc_icon = $clt_social('Social_Icon');
    if($soc_show === 'active'){
        do{
            echo '<a class=\"'.$soc_class.'\" href=\"'.$soc_url.'" style=\"color:#fff\" <i class=\"'.$soc_icon.'\"</i></a>&nbsp;&nbsp';
        }while ($clt_social = mysql_fetch_assoc($clt_soc));
    }
}

现在我将此函数称为<?php cltsocial() ?>

但是显示错误

  

Fatal error: Function name must be a string in C:\xampp\htdocs\mywebsite\incl\functions\functions.php on line 87

我无法找到我的错......我该怎么办?

1 个答案:

答案 0 :(得分:0)

  1. 您必须像这样调用您的函数,请注意最后的;

    <?php 
        cltsocial(); 
    ?>
    

    即使它是一行,您也应该使用;

  2. 来终止它
  3. $ctl_social是一个数组,而不是函数:

    这些:

    $soc_show = $clt_social('SocialShow');
    $soc_class = $clt_social('SocialClass');
    $soc_url = $clt_social('SocialUrl');
    $soc_icon = $clt_social('Social_Icon');
    

    应该是:

    $soc_show = $clt_social['SocialShow'];
    $soc_class = $clt_social['SocialClass'];
    $soc_url = $clt_social['SocialUrl'];
    $soc_icon = $clt_social['Social_Icon'];
    
  4. 此外,作为建议,您不应使用mysql扩展程序,使用mysqliPDO扩展名和预备语句Here's why