Search
Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Echo all data from a fetched object if equal to the conditio
  This user is offline  b321618
  Subject: "Echo all data from a fetched object..." Posted: @ 10:24 pm on May 28 2009   
Member #: 946
Rank: User - (7)
Since: 05/28/09
Posts: 7

Hello all! ok im making a comment system with a a reply option,
but my problem is when I have the reply show up under the comment it only shows the first reply that is equal to the comments ID, even through there might be 5 or 6 replys that are equal to the comment.
So my replys have the same ID as the comment, so I have a mysql_fetch_obj ect function set to retrive any reply id equal to the comment ID, and that works! but it only shows the first reply in the table that is equal to the condition, I need it to show all and any equal to the condition...


Code:
$inf = "SELECT * FROM comments WHERE page = '".stripsl ashes($_SERVER[ 'REQUEST_URI']) ."' ORDER BY time DESC";
$info = mysql_query($in f);

if(!$info) die(mysql_error ());

$info_rows = mysql_num_rows( $info);
if($info_rows > 0)
{
echo '<br>Comm ents:<br> ';
echo '<table width="50% "><b r>';

while($info2 = mysql_fetch_obj ect($info))
{
;
$infr = "SELECT * FROM reply WHERE commentidr = '".$info2- >id."' ORDER BY timer DESC";
$infor = mysql_query($in fr);
while($info2r = mysql_fetch_obj ect($infor))
{
$replyr = $info2r->rep lyr;
$commentidr = $info2r->com mentidr;
$usernamer = $info2r->use rnameapr;
}
echo '<tr>';
echo '<td>< div align="cen ter">&l t;b>'.$info2 ->username.' <br> '.date('h:i:s a', $info2->time ).' on '.$info2->da te.'</b>& lt;/div>< /td>';
echo '</tr>< ;tr>';
echo '<td colspan="2 "><d iv align="cen ter">'. stripslashes($i nfo2->commen t).'<br>' .stripslashes($ info2->reply box).'<br> ;'.$usernamer.' <br>'.$re plyr.'<br> ;<div>< ;/td>';



Edited at 10:26:05 pm on 05/28/09


    Viewed: 3,655 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Echo all data from a fetched ob..." Posted: @ 10:43 pm on May 28 2009    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Hmm, let me know what this does:

Code:

<?
//query comments
$inf = "SELECT * FROM comments WHERE page = '".strip slashes($_SERVE R['REQUEST_URI '])."' ORDER BY time DESC";
$info = mysql_query($in f);
if(!$info) die(mysql_error ());

$info_rows = mysql_num_rows( $info);
if($info_rows > 0) {
echo '<br>Com ments:<br> ;';
echo '<table width="50 %">< ;br>';
} //end if

while($info2 = mysql_fetch_obj ect($info)) { //show comments

echo '<tr>';
echo '<td>< ;div align="ce nter"> <b>'.$in fo2->usernam e.' <br> '.date('h:i:s a', $info2->time ).' on '.$info2->d ate.'</b> ;</div>&l t;/td>';
echo '</tr>&l t;tr>';
echo '<td colspan=" 2">< ;div align="ce nter"> '.stripslashes ($info2->com ment).'<br& gt;'.stripslas hes($info2-> replybox).'< ;br><div& gt;</td> ';

//query replies
$infr = "SELECT * FROM reply WHERE commentidr = '".$info 2->id." ;' ORDER BY timer DESC";
$infor = mysql_query($in fr);
if(!$infor) die(mysql_error ());

if(mysql_num_ro ws($infor) >= 1) { //if 1 or more replies,
while($info2r = mysql_fetch_obj ect($infor)) { //show replies

echo '<tr>';
echo '<td>< ;div align="ce nter"> <b>'.$in fo2r->userna meapr.' <br> '.date('h:i:s a', $info2r->tim e).' on '.$info2r-> date.'</b&g t;</div>& lt;/td>';
echo '</tr>&l t;tr>';
echo '<td colspan=" 2">< ;div align="ce nter"> '.stripslashes ($info2r->re plyr).'<br& gt;'.stripslas hes($info2r-> ;replybox).'&l t;br><div ></td> ';
} //end if
} //end while (replies)
} //end while (comments)
?>
</table>< /div>




-bs0d | AllSyntax.com

    Viewed: 3,645 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank