Foser Posted February 1, 2008 Share Posted February 1, 2008 $query = mysql_query("SELECT `post_subject`, post_text FROM `phpbb_posts` WHERE `forum_id` = 2 ORDER by `post_id` DESC LIMIT 2"); $article = mysql_fetch_assoc($query); this is what I have. I'd like to keep it assoc but if it's easier another way I'm flexible for it. I would know how to echo it out in normal if it was limit 1 but as limit 2 how can I differentiate from $article['post_subject'] (for first in order) and $article['post_subject'](from limit two) thanks, any help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/ Share on other sites More sharing options...
jordanwb Posted February 1, 2008 Share Posted February 1, 2008 Just use != (Not equals) and compare between the two. Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455361 Share on other sites More sharing options...
Foser Posted February 1, 2008 Author Share Posted February 1, 2008 Just use != (Not equals) and compare between the two. could you elaborate? Don't see how that condition would work... Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455373 Share on other sites More sharing options...
jordanwb Posted February 1, 2008 Share Posted February 1, 2008 Well when you loop through the first row save $article['post_subject'] to it's own variable so it won't be lost. Then when it goes into the second row compare that row's $article['post_subject'] to the variable you just created. Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455378 Share on other sites More sharing options...
Foser Posted February 1, 2008 Author Share Posted February 1, 2008 Well the only thing is. I want it seperatly but with the same query as I won't be using a loop. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455383 Share on other sites More sharing options...
jordanwb Posted February 1, 2008 Share Posted February 1, 2008 So basically what you're doing is: Run the query and save the result Get the first row and do some stuff with it A little further down get the second row. Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455620 Share on other sites More sharing options...
BrandonK Posted February 1, 2008 Share Posted February 1, 2008 You can throw them to a 3d array: while ($fetch = mysql_fetch_assoc($query) { $article[] = $fetch; } echo $article[0]['post_subject']; //row 1 echo $article[1]['post_subject']; //row 2 Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455686 Share on other sites More sharing options...
jordanwb Posted February 1, 2008 Share Posted February 1, 2008 Yes that would work. Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455698 Share on other sites More sharing options...
Psycho Posted February 2, 2008 Share Posted February 2, 2008 <?php $query = mysql_query("SELECT `post_subject`, post_text FROM `phpbb_posts` WHERE `forum_id` = 2 ORDER by `post_id` DESC LIMIT 2"); $article1 = mysql_fetch_assoc($query); $article2 = mysql_fetch_assoc($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88902-mysql-query-limit-2/#findComment-455744 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.