开发者

why is this code displaying all comments?

开发者 https://www.devze.com 2023-03-23 15:32 出处:网络
I\'ve got the code displaying comments but it\'s displaying all comments not just ones that are equal, can\'t figure this out.

I've got the code displaying comments but it's displaying all comments not just ones that are equal, can't figure this out.

<?php
$sql = "SELECT * FROM contactnotes,contacts WHERE contactnotes.contacts_id = contacts.ID ORDER BY contactnotes.timestamp DESC" or die('Error: ' .mysql_error());

$result = mysql_query($sql) or die ('Error: ' .mysql_error());

while ($row = mysql_fetch_array($result)){

?>

<table width="950" border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="left" width="100%"><h5><strong><? echo $row['agentassigned']; ?> 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>
<开发者_C百科/table>
<hr/>
<br />


I'm assuming you are looking to show all notes for a contact, try rewriting your query as follows:

"SELECT * FROM contactnotes,contacts WHERE contactnotes.contacts_id = contacts.ID AND contacts.ID = " . mysql_real_escape_string($id) . " ORDER BY contactnotes.timestamp DESC"


FYI:

$sql = "SELECT * FROM ..... DESC" or die('Error: ' .mysql_error());

You're doing a string assignment, not a MySQL operation. Assignments cannot fail in PHP, so the or die() will NEVER be triggered, and it's not a MySQL operation, so even if the assignment did somehow miraculously fail, the error message would be completely wrong and utterly useless.

0

精彩评论

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