runnerjp Posted November 10, 2008 Share Posted November 10, 2008 for some reason when i shorten my code form <?php $getreplies = "Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime DESC LIMIT 0, 10"; //getting replies $getreplies2 = mysql_query($getreplies) or die(mysql_error() . "Could not get replies"); while ($getreplies3 = mysql_fetch_array($getreplies2))?> to <?php $getreplies3 = mysql_fetch_assoc(mysql_query("Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime DESC LIMIT 0, 10"));?> it only shows one result rather then 10.... how comes? Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/ Share on other sites More sharing options...
bobbinsbro Posted November 10, 2008 Share Posted November 10, 2008 because you only run mysql_fetch_assoc once, where in the longer code, you have a while loop Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/#findComment-686586 Share on other sites More sharing options...
runnerjp Posted November 10, 2008 Author Share Posted November 10, 2008 ahh yes... is there away to add the while loop into the shortend code? Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/#findComment-686587 Share on other sites More sharing options...
kenrbnsn Posted November 10, 2008 Share Posted November 10, 2008 You need the loop to fetch all of the entries. The query only gets a pointer to the retrieved set. The fetch actually gets the data, one row at a time. BTW, leave the 3 lines -- it's much easier to debug if anything goes wrong. Ken Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/#findComment-686588 Share on other sites More sharing options...
runnerjp Posted November 10, 2008 Author Share Posted November 10, 2008 ok cheers Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/#findComment-686589 Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 BTW, leave the 3 lines -- it's much easier to debug if anything goes wrong. Ken Exactly. Do not sacrifice your code readability for filesize. This is not the 1980's when every byte counted. Shortening your code like that is like the difference between you trying to decide whether to drive down to storeA or to storeB that's next door. You won't even factor into the equation the distance, because in your eyes, it's the same, because it's like, next door. Quote Link to comment https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/#findComment-686675 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.