开发者

pulling data from multiple tables on the same page

I'm stuck on this code and can't figure out where I need to go. I'm trying to pull name, phone number and email from table "contacts" which is dispayed on page and on the same page post notes to table "contactnotes" and then display them unde开发者_StackOverflow中文版r the textbox. I can't figure out how to do it all on the same page. Here is what I have thus far.

 <?php
 mysql_connect ("link","db","pw") or die ('Error: ' .mysql_error());
 mysql_select_db ("db");

 $ID = $_GET['ID'];
 $notes = $_POST['notes'];

 $query="INSERT INTO contactnotes (id, notes)VALUES ('NULL', '".$notes."')";

 mysql_query($query) or die ('Error Updating Database');


 $sql = "SELECT * FROM contacts WHERE ID='$ID' limit 1" or die ('Error: ' .mysql_error());
 $result = mysql_query($sql) or die ('Error: ' .mysql_error());

 while ($row = mysql_fetch_array($result);

 ?>

 <!-- CONTACT INFO -->
 <div id="contact-table"><?php include("contact-info.php"); ?></div>
 <br />
 <form method="post" action="/db/notes.php?ID=<? echo $row['ID']; ?>"/>
 <input type="hidden" value="<? echo $row['id']; ?>" name = "id" id="id"/>  
 <br />

 <input type="submit" value="Edit Contact">
 <input type="submit" value="Delete Contact">
 <br />
 <br />
 <hr />
 <table border="0" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
 <tr>
 <td><strong>Notes</strong></td>
 </tr>
 <tr>  
 <td><textarea name="notes" id="notes" rows="5" cols="100"></textarea></td>
 </tr>
 </table>
 <br />
 <hr/>
 <br />
 <table width="950" border="0" cellspacing="0" cellpadding="3">
 <tr>
 <td align="left" width="100%"><h5><strong><? echo $row['user']; ?> on <? echo date("F d Y @ h:i:s", strtotime($row['timestamp'])); ?> wrote:</strong></h5></td>
 </tr>
 <tr>
 <br />
 <td align="left" width="100%"><? echo $row['notes']; ?></td>
 </tr>
 </table>
 <hr/>
 <br />
 <input type="submit" value="Edit Contact">
 <input type="submit" value="Delete Contact">
 </form>
 <?
 mysql_close();
 ?>


Check out MySQL JOIN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜