douchigu1723 2014-06-20 08:13
浏览 51
已采纳

错误在哪里?

I am trying to create social links.

My database fields are

----------------------------------------------------------------------------------------------------------------------
| 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          |
----------------------------------------------------------------------------------------------------------------------

and for this, I coded like below:

// 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));
    }
}

Now I call this function like this <?php cltsocial() ?>

But there's an error showing

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

I am unable to find my fault... What should I do?

  • 写回答

1条回答 默认 最新

  • duanlan4801 2014-06-20 08:23
    关注
    1. You must call your function like this, note the ; at the end:

      <?php 
          cltsocial(); 
      ?>
      

      Even if it's a single line, you should terminate it with a ;

    2. $ctl_social is an array, not a function:

      These:

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

      Should be:

      $soc_show = $clt_social['SocialShow'];
      $soc_class = $clt_social['SocialClass'];
      $soc_url = $clt_social['SocialUrl'];
      $soc_icon = $clt_social['Social_Icon'];
      

    Also, as a suggestion, you shouldn't be using the mysql extensions, either use the mysqli or PDO extensions and prepared statements. Here's why.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名