Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2006, 06:56 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default What's wrong with my While Loop?

Does anyone see something wrong with the while loop below? It's only returning 1 string, when there are in fact more than 10.

PHP Code:
 $thread_sql mysql_query("SELECT threadid,title,lastpost,lastposter,forumid FROM thread WHERE visible=1 $wheresql AND open=1 ORDER BY lastpost DESC LIMIT 10");
 
 while(
$thread_get=mysql_fetch_array($thread_sql))
 {
 
$lastpost $thread_get['lastpost'];
 
$poster $thread_get['lastposter'];
 
$tid $thread_get['threadid'];
 
$psql mysql_query("SELECT postid FROM post WHERE threadid=$tid ORDER BY postid DESC");
 
$getp=mysql_fetch_array($psql);
 
$pid $getp['postid'];
 
$date2 date ("m/d/y h:i A" ,$lastpost);
 
$title $thread_get['title'];
 
$title substr($title,0,$txtlimit);
 
$output "$title";
 } 
Reply With Quote
  #2  
Old 10-14-2006, 07:03 PM
Guest190829
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by acidburn0520
Does anyone see something wrong with the while loop below? It's only returning 1 string, when there are in fact more than 10.

PHP Code:
 $thread_sql mysql_query("SELECT threadid,title,lastpost,lastposter,forumid FROM thread WHERE visible=1 $wheresql AND open=1 ORDER BY lastpost DESC LIMIT 10");
 
 while(
$thread_get=mysql_fetch_array($thread_sql))
 {
 
$lastpost $thread_get['lastpost'];
 
$poster $thread_get['lastposter'];
 
$tid $thread_get['threadid'];
 
$psql mysql_query("SELECT postid FROM post WHERE threadid=$tid ORDER BY postid DESC");
 
$getp=mysql_fetch_array($psql);
 
$pid $getp['postid'];
 
$date2 date ("m/d/y h:i A" ,$lastpost);
 
$title $thread_get['title'];
 
$title substr($title,0,$txtlimit);
 
$output "$title";
 } 
What is $psql? You really shouldn't be running a query inside a while loop. It can cause intense server load.

By results, do you mean the value of $output?

If so, you are not appending your results to a variables just setting the variable with each new row.
Reply With Quote
  #3  
Old 10-14-2006, 07:22 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's an excerpt from a script I got somewhere from here. So, what exactly is wrong with it?
Reply With Quote
  #4  
Old 10-14-2006, 07:31 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It looks like it could do with rewriting, what's it supposed to be doing ?
Reply With Quote
  #5  
Old 10-14-2006, 07:34 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Getting the latest posts from specific forums. Like I said, I was in a hurry and just took it from some old post.
Reply With Quote
  #6  
Old 10-14-2006, 07:42 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You are resetting it every time with your assignments. Use .= if you want to add to a string instead.

PHP Code:
$string .= 'add this'
Reply With Quote
  #7  
Old 10-14-2006, 07:56 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by acidburn0520
Getting the latest posts from specific forums. Like I said, I was in a hurry and just took it from some old post.
Then its a dreadful piece of code. You would be better throwing it away and looking/asking for something better.
Reply With Quote
  #8  
Old 10-14-2006, 08:05 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Shoot. Have to end up writing in after all, oh well. Thanks.
Reply With Quote
  #9  
Old 10-14-2006, 11:13 PM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I wrote this a while back.

PHP Code:
$getthreads $db->query_read("SELECT * FROM " TABLE_PREFIX "thread WHERE forumid='5' ORDER BY threadid DESC LIMIT 10");    
while(
$lt $db->fetch_array($getthreads))
{
   
$latestthreads .= "Title: <a href='showthread.php?t=$lt[threadid]'>".$lt['title']."</a> | Posted By: <a href='member.php?u=$lt[postuserid]'>".$lt['lastposter']."</a><br />";


Reply With Quote
  #10  
Old 10-14-2006, 11:22 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Harmor. I actually already wrote one, basically the same - only I didn't know how to get the lastpostuserid. Thanks, though.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:42 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04676 seconds
  • Memory Usage 2,265KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (9)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete