質問

I'm currently making some internet forums using php and mysql, and I have hit a roadblock... I don't know how to implement the constraints in need for this, or even how to implement it into my site exactly (sql trigger or procedure or php script?).

So anyways, Ihave a db named blog, with two tables: posts and threads. In the posts table there are two columns that would be involved in this, reply_id and parent_id, on each insert into the posts table, I need the just inserted row's reply_id to be set as the threads' table topic_order, where topic_id=parent_id...

The page that displays the topics, sorts them by highest topic_order, thus higher reply_id would mean a higher topic_order, and would bump a thread to the top of the list.

$result_t = mysqli_query($con,"SELECT * FROM threads WHERE board_id='$row_b[board_id]' ORDER BY topic_order DESC");

This is currently being displayed http://fenster.myftp.org/blog/forums/board.php?id=1

An sql trigger was what I needed and through trial and error I found that I could use reply_id to find which row was just inserted and then limit it to only that row's data

CREATE TRIGGER `bump` AFTER INSERT ON `posts`
 FOR EACH ROW UPDATE threads
SET topic_order=(SELECT reply_id FROM posts ORDER BY reply_id DESC LIMIT 1)
WHERE topic_id=(SELECT parent_id FROM posts ORDER BY reply_id DESC LIMIT 1)
役に立ちましたか?

解決

replace this

    WHERE board_id='$row_b[board_id]'

by

   WHERE board_id='".$row_b['board_id']."'
                            ^--------^--------you need quotes here
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top