conker87 Posted October 25, 2006 Share Posted October 25, 2006 I'm running an article service, and would like comments to be added by people.Tables as follows:articleid, title, author, type, content, copyrightcommentid, name, comment, article_idHere is the code I'm using:[code] $queryi = "SELECT comment.name, comment.comment, comment.article_id, article.id FROM comment INNER JOIN article ON comment.article_id=article.id" or die ("Unable to find data"); $resulti = mysql_query($queryi) or die("Error:<br>". mysql_error(). "<br>With query:<br>". $queryi); $numi = mysql_fetch_array($resulti); //mysql_numrows($resu1ti); if (!($numi == 0)) { echo "<p>"; $ii = 0; while ($ii < $numi) { $name = mysql_result($resulti,$ii,"name"); $comment = mysql_result($resulti,$ii,"comment"); echo "<b>$name</b>"; echo "<p>$comment"; echo "<br><hr size='1' color='#FF0000'></p>"; $ii++; } echo "</p>";[/code]This code infinitely loops, showing the test comment I posted, yet also throwing up the following error hundreds of times:[quote]Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 7 in /home/fr29leag/public_html/article.php on line 97Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 7 in /home/fr29leag/public_html/article.php on line 98[/quote]I'm also noticing it's doing this for all articles and not just the article I posted the test comment on.Anyone know what's wrong? Any help would be appriciated. Quote Link to comment Share on other sites More sharing options...
shoz Posted October 25, 2006 Share Posted October 25, 2006 [quote author=conker87 link=topic=112682.msg457418#msg457418 date=1161787713][code] $queryi = "SELECT comment.name, comment.comment, comment.article_id, article.id FROM comment INNER JOIN article ON comment.article_id=article.id" or die ("Unable to find data"); $resulti = mysql_query($queryi) or die("Error:<br>". mysql_error(). "<br>With query:<br>". $queryi); $numi = mysql_fetch_array($resulti); //mysql_numrows($resu1ti);[/code][/quote]Looks like you want the following for your $numi assignment [code]$numi = mysql_num_rows($resu1ti);[/code]You can use mysql_fetch_array or mysql_fetch_assoc in the following way to go through results[code]$query = '..';$result = mysql_query....if (mysql_num_rows($result)){ while ($row = mysql_fetch_assoc($result)) { echo $row['name']."<br />\n".$row['comment']."<br /><br />\n\n"; }}[/code]http://www.php.net/mysql_fetch_assoc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.