从同一页面上的多个表中提取数据

时间:2011-07-26 04:07:25

标签: php mysql

我坚持使用此代码,无法弄清楚我需要去哪里。我试图从表格中删除姓名,电话号码和电子邮件,然后是#34;联系人"这是在页面上和同一页面上发布的,将注释发布到表格" contactnotes"然后在文本框下显示它们。我无法弄清楚如何在同一页面上完成所有操作。这是我到目前为止所做的。

 <?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();
 ?>

1 个答案:

答案 0 :(得分:0)

查看MySQL JOIN