Page 1 of 1
query help...
Posted: Wed Mar 23, 2005 2:37 am
by pleigh
i have code here
Code: Select all
$query = "SELECT DATE_FORMAT(commentdate, '%M %D, %Y - %l:%i %p'), username, comment, commentID FROM
comments WHERE postID='$id' ORDER BY commentdate DESC";
$result = @mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num > 0)
{
$uname = $_SESSION['firstname'];
//report edit
$editquery = "SELECT postID, username, commentID FROM comments
WHERE postID='$id' AND username='$uname'";
$editresult = @mysql_query($editquery) or die(mysql_error());
if ($row = mysql_fetch_assoc($editresult))
{
$edit = '<a href="reportcommentedit.php?eid='.$_GET['pid'].'&cid='.$row['commentID'].'" class=under>EDIT</a>';
}
else
{
$edit = ' ';
}
this is to get both the eid and the cid from here to another page...it works...but the problem is that when there are 2 or more edit link, their cid is the same....so when i edit the the last comment, the it is changing the first comment, and not the current comment....i know there's something wrong about my query...can you help me guys?
thanks
Posted: Wed Mar 23, 2005 8:03 am
by feyd
is it the links (line 15) that aren't showing up correctly, or the edit bits on the following page?
Posted: Tue Mar 29, 2005 12:08 am
by pleigh
thanks feyd...yes, line 15 is not showing correclty and the edit page...when, for example, i have 2 edit links, they both show the same cid, the value of the first comment is "apple", the 2nd is "banana", apple is the latest comment posted, when i click the edit of the 2nd comment, which is banana, the edit form loads and the value of the textarea is apple...
Posted: Tue Mar 29, 2005 5:23 am
by feyd
well, you aren't looping over the results that are affected by that call, so I'd assume it's that.
Posted: Tue Mar 29, 2005 5:28 am
by pleigh
for the complete script...
Code: Select all
<?
$query = "SELECT DATE_FORMAT(commentdate, '%M %D, %Y - %l:%i %p'), username, comment, commentID FROM
comments WHERE postID='$id' ORDER BY commentdate DESC";
$result = @mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num > 0)
{
$uname = $_SESSION['firstname'];
//comment edit
$editquery = "SELECT postID, username, commentID FROM comments
WHERE postID='$id' AND username='$uname'";
$editresult = @mysql_query($editquery) or die(mysql_error());
if ($row = mysql_fetch_assoc($editresult))
{
$edit = '<a href="reportcommentedit.php?eid='.$_GET['pid'].'&cid='.$row['commentID'].'" class=under>EDIT</a>';
}
else
{
$edit = ' ';
}
//for comment
if ($num <= 1)
{
$c = 'Comment';
}
else
{
$c = 'Comments';
}
echo "
<tr valign=top class=tablehead align=center>
<td width=15% class=tablehead><table><tr><td><font color=#ffffff><b/>Author</font></td></tr></table></td>
<td width=85% class=tablehead><table><tr><td><font color=#ffffff><b/>$c</font></td></tr></table></td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$row[0] = '<font size=1>'.$row[0].'</font>';
echo "
<tr valign=top>
<td width=15% class=tableborder align=center><table><tr><td align=center>$row[1]<br>$row[0]</td></tr></table></td>
<td width=85% class=tableborder><table><tr><td>
<table width=100%>
<tr valign=top width=20%><td width=100%>".nl2br($row[2])."</td></tr>
<tr valign=top width=20%><td width=100%>$edit</td></tr>
</table>
</td></tr></table></td>
</tr>";
}
}
else
{
echo NULL;
}
?>
i don't know where the problem is...
Posted: Tue Mar 29, 2005 5:47 am
by feyd
you aren't looping over the results. You requested a single record, nothing more.
Posted: Tue Mar 29, 2005 6:21 am
by pleigh
Code: Select all
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$row[0] = '<font size=1>'.$row[0].'</font>';
echo "
<tr valign=top>
<td width=15% class=tableborder align=center><table><tr><td align=center>$row[1]<br>$row[0]</td></tr></table></td>
<td width=85% class=tableborder><table><tr><td>
<table width=100%>
<tr valign=top width=20%><td width=100%>".nl2br($row[2])."</td></tr>
<tr valign=top width=20%><td width=100%>$edit</td></tr>
</table>
</td></tr></table></td>
</tr>";
}
isn't this the loop youre looking??