小编Mal*_*lik的帖子

您的 SQL 语法有错误;检查与您的 MySQL 服务器相对应的手册

我编写了代码来尝试在我的论坛上进行用户活动,并在添加此行时

$cat_id = $db->fetch("SELECT name FROM " . $prefix . "_categories WHERE id =" . mysql_real_escape_string($forum_data['cat_id']));
$page_title_pro = ' > ' . $system->present($cat_id['name']) . ' > ' . $system->present($forum_data['name']) . '';
Run Code Online (Sandbox Code Playgroud)

我得到

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Treasures > Contests' WHERE id = '2'' at line 1
Run Code Online (Sandbox Code Playgroud)

我假设 2 是我的用户 ID,在页脚中,我有这个:

$db->query("UPDATE accounts SET flocation = '$session_location', page = …
Run Code Online (Sandbox Code Playgroud)

php mysql sql

2
推荐指数
1
解决办法
6810
查看次数

循环后的逗号

我想为除了最后一个用户名之外的每个用户名添加一个逗号.例如:User1,User2,User3我该怎么做?这是我的代码:

$user_online_sql = $db->query("SELECT DISTINCT account_id FROM online WHERE account_id != '-1';");
$users = '';
while ($user_online_row = mysql_fetch_array($user_online_sql)) {
$users .= $user->name($user_online_row['account_id']) . ' ';
}
Run Code Online (Sandbox Code Playgroud)

我尝试了implode函数,但它只是输出一个空白结果,这里是带有implode函数的代码:

 $user_online_sql = $db->query("SELECT DISTINCT account_id FROM online WHERE account_id != '-1';");
$users = '';
while ($user_online_row = mysql_fetch_array($user_online_sql)) {
$users .= implode(', ',$user->name($user_online_row['account_id'])) . ' ';
} 
Run Code Online (Sandbox Code Playgroud)

php

0
推荐指数
1
解决办法
49
查看次数

标签 统计

php ×2

mysql ×1

sql ×1