|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
topics and posts
ok, got another one thats been teasing my brain..When someone creates a new topic on my forum, it has to create both a new field in the topics table, and the posts table. Although, I need the field in the posts table to have the linking topic_id, which links it to the topic, but this I am having trouble with, as im trying to create both the field in the posts and topic table at the same time, so i dont know what the new topic_id will be. Is there anyway of doing this?
Sorry if it didnt make much sense |
|
#2
|
|||
|
|||
|
RE: topics and posts
Apology accepted.
Assuming we're talking about creating a new record and not a new field in the two tables ... do it multiple steps. Insert the record into topics_table, which will be assigned a unique topic_id, which is probably set to auto increment(another assumption). Then query the topics_table by topic_id and sort desc. Take that and insert a new record into your posts_table. HTH |
|
#3
|
|||
|
|||
|
RE: topics and posts
oooh, cheers dude
|
|
#4
|
|||
|
|||
|
RE: topics and posts
It might be better to query using max(id) instead of returning all the rows sorted by desc. If you are using an auto-increment field for id,you can use mysql_insert_id(), which:
"mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed" - php.net I'm not a big fan of auto-increment, but if you do use it, that is a very useful function Cheers, Keith. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > topics and posts |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|