Jump to content

[SOLVED] short coding not working right...


runnerjp

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/132118-solved-short-coding-not-working-right/
Share on other sites

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

 

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.