need a better method for a snippet in php
<p>Say I have a database  called <code>Poll</code> and have these two table structures. <code>poll</code> table has fields <code>pid</code> (auto_inc) and <code>title</code>. <code>choices</code> table has <code>cid</code> (auto_inc), <code>pid</code>, and <code>text</code>. </p>

<p>How do i add a value to the <code>poll</code> table and at the same time get the <code>pid</code> of the most recent entry in the <code>poll</code> table to be used as the <code>pid</code> in the <code>choices</code> table? So far I have this:</p>

<pre><code>&lt;?php
$sql = "INSERT INTO poll (pid, title) VALUES (NULL, 'sometitle')";
if (mysql_query($sql)) {
  // get the latest pid
  $pid = mysql_result(mysql_query("SELECT pid FROM poll ORDER BY pid DESC LIMIT 1"), 0);

  // use the latest pid retrieved to insert to the "choices" table
  $sql = "INSERT INTO choices (cid, pid, text) VALUES (NULL, " . $pid . ", 'sometext')";
  mysql_query($sql);
}
?&gt;
</code></pre>

<p>I just have a feeling that there's a better solution to this.</p>

<p>Thanks!</p>
