我正在尝试创建社交链接。
我的数据库字段是
----------------------------------------------------------------------------------------------------------------------
| 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>  ';
}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
我无法找到我的错......我该怎么办?
答案 0 :(得分:0)
您必须像这样调用您的函数,请注意最后的;
:
<?php
cltsocial();
?>
即使它是一行,您也应该使用;
$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'];
此外,作为建议,您不应使用mysql
扩展程序,使用mysqli
或PDO
扩展名和预备语句 。 Here's why