title: 2-table interaction: insert, get result, insert
body: <p>I need to make a fundamental decision of my database/web interaction and I am missing the knowledge to even find proper search terms.</p>
  <h3>Background:</h3>
  <p>I am building a family website which supports a forum, family tree, pvp games with rankings and more details, all from a datamodel. Technologies right now: Php, MySQL, javascript in object oriented fashion.</p>
  <h3>Requirement:</h3>
  <p>In a forum datamodel, process a written post as addition of a new forum topic (thread).</p>
  <h3>Current approach:</h3>
  <p>In my current datamodel this would imply and update on two tables: Post and Topic.
  I would need to <strong>insert a row in the topic table, then get the newly generated topicId(sequence), and then use that in an insert to the post table</strong>.</p>
  <h3>Problem:</h3>
  <p><strong>I feel this is too much work</strong> for what needs to happen, too much interaction.
  But it will become a typical requirement if I stick with the current approach.</p>
  <p>Question:</p>
  <ol>
  <li>am I on the right track anyway or should I</li>
  <li>restructure the datamodel or</li>
  <li>pick another way of database interaction (e.g. stored procedures)</li>
  <li>am I facing a typical example where you would use methodology/framework xyz.</li>
  </ol>
  <p>Currently tables have following structure (loosely based on <a href="http://www.erdiagrams.com/datamodel-forum-idef1x.jpg" rel="nofollow noreferrer">this one</a> from erdiagrams.com)</p>
  <p><strong>TOPIC</strong>: ('thread')</p>
  <pre><code>id
  Forum_ID (FK)
  Person_ID (FK)(threadcreator)
  IsLocked
  IsSticky
  Subject
  ViewCount
  DateCreated
  Tc_post_id  - trigger to last post_id in this thread
  </code></pre>
  <p><strong>POST</strong></p>
  <pre><code>id
  topic_id(FK)
  person_id(FK)
  subject
  message
  timestamp
  replyto
  </code></pre>
  <p>Then I have a view that collects the last post for each topic and displays some info on that as well (e.g. last poster image) over the trigger Tc_post_id.</p>