开发者

MySQL syntax Error; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4

I get the following mySQL error listed below and was wondering how can I fix it.

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 ')' at line 4

Here is my MySQL code below.

$q = "SELECT COUNT(DISTINCT tags.tag) FROM tags INNER JOIN articles_tags ON articles_tags.tag_id = tags.id INNER JOIN users ON articles_tags.user_id = users.user_id WHERE users.active IS NULL AND users.deletion = 0";
$r = mysqli_query ($mysqli, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($mysqli));
$row = mysqli_fetch_array ($r);
$records = $row开发者_运维问答[0];

Here is my tables.

CREATE TABLE tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);


CREATE TABLE articles_tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_id INT UNSIGNED NOT NULL,
article_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
date_created DATETIME NOT NULL,
unique_id CHAR(32) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY (tag_id, unique_id)
);


The query seems to be ok... i supose this can be an issue because of DISTINCT function...
Try this:

$q = "SELECT COUNT(tags.tag) FROM tags INNER JOIN articles_tags ON articles_tags.tag_id = tags.id INNER JOIN users ON articles_tags.user_id = users.user_id WHERE users.active IS NULL AND users.deletion = 0 GROUP BY tags.tag";


The mysql_fetch_array needs 2 arguments. It is

mysql_fetch_array(result, result_type)

Possible result types are MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.

You might want to also see the mysql_fetch_assoc function which could be of help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜