I have two Posts tables like these:
// Posts_1
+----+----------+---------------------------------------------+
| id | word | mean |
+----+----------+---------------------------------------------+
| 1 | hello | an utterance of “hello”; a greeting. |
| 2 | what | asking for information specifying something |
| 3 | light | provide with light or lighting; illuminate |
+----+----------+---------------------------------------------+
// Posts_2
+----+----------+---------------------------------------------+-----------+
| id | word | mean | author |
+----+----------+---------------------------------------------+-----------+
| 1 | inorite | I know, right | Sajad |
| 2 | dunno | I don't know | Jack |
| 3 | lemme | let me | Ali |
+----+----------+---------------------------------------------+-----------+
Note: I can't create just one table instead of those two Posts tables. (according to some reasons in reality)
Also I have a Votes table Like this:
// Votes
+----+---------+------------+---------+-----------+
| id | post_id | table_name | user_id | timestamp |
+----+---------+------------+---------+-----------+
And Here is my query to insert a new vote:
INSERT INTO Votes (post_id, table_name, user_id, value, timestamp)
SELECT $post_id, $table_name, $user_id, $value, $timestamp
FROM Dual
WHERE { ? }
Actually I need to a condition which checks if current vote is belong to a such Posts table which has author column , then check this:
... WHERE $author = (SELECT author_id FROM $table_name WHERE id = $post_id)
Note: $table_name is either Posts_1 or Posts_2.
Well, Actually I want to give some reputation to author of that post which has achieved a vote. And I need to check $author (if exists) with real author of that post in the database. Is there any solution?
Aucun commentaire:
Enregistrer un commentaire