vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What's wrong with my While Loop? (https://vborg.vbsupport.ru/showthread.php?t=129089)

Kirk Y 10-14-2006 05:56 PM

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";
 } 


Guest190829 10-14-2006 06:03 PM

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.

Kirk Y 10-14-2006 06:22 PM

It's an excerpt from a script I got somewhere from here. So, what exactly is wrong with it?

Paul M 10-14-2006 06:31 PM

It looks like it could do with rewriting, what's it supposed to be doing ?

Kirk Y 10-14-2006 06:34 PM

Getting the latest posts from specific forums. Like I said, I was in a hurry and just took it from some old post.

Adrian Schneider 10-14-2006 06:42 PM

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

PHP Code:

$string .= 'add this'


Paul M 10-14-2006 06:56 PM

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.

Kirk Y 10-14-2006 07:05 PM

Shoot. Have to end up writing in after all, oh well. Thanks.

harmor19 10-14-2006 10:13 PM

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 />";




Kirk Y 10-14-2006 10:22 PM

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


All times are GMT. The time now is 11:02 AM.

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.01716 seconds
  • Memory Usage 1,751KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete