2012-11-14 32 views
0

我具備的功能:PHP MySQL的功能顯示在HTML

function get_current_users($current_users) 
{ 
global $db; 
$current_users = $db->EscapeString($current_users); 
$total_current_users = $db->QueryFetchArray("SELECT COUNT(*) FROM users AS total_current_users"); 
return $total_current_users['total_current_users']; 

}

但我不知道如何輸出結果,我試過下面的選項,但沒有顯示:

`<?$total_current_users?> 
<?['$total_current_users']?> 
<?=data['$total_current_users']?>` 

回答

0

如果你確信你的函數做什麼它應該,我想這兩個等效方法將獲得你的輸出:

<?= get_current_users() ?><?php echo get_current_users() ?>

作爲說明:我沒有看到您轉義的論點$current_users,因爲它在後續查詢中永遠無法使用。

0

試試這個語法

$total_current_users = $db->QueryFetchArray("SELECT COUNT(*) as total_current_users FROM users"); 

您正在從結果集中選擇一個要返回的值,該值未命名,請嘗試上述以使其與您的代碼匹配。

然後更改模板代碼爲:<?php echo $total_current_users; ?>

+0

當我在我的functions.php中使用該語法時,該網站只顯示空白,如果有任何方法來使用函數來格式化上面的示例嗎? – CustomNet

+0

在改變任何東西之前,我們應該看看你的函數正在做什麼,請在你的函數中,在'return'add'var_dump($ total_current_users);'這應該告訴你查詢是否做任何事情。 –