PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old August 1st, 2002, 09:22 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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

Reply With Quote
  #2  
Old August 1st, 2002, 11:06 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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

Reply With Quote
  #3  
Old August 1st, 2002, 11:33 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: topics and posts

oooh, cheers dude

Reply With Quote
  #4  
Old August 1st, 2002, 12:57 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > topics and posts


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway