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 01-20-2006, 08:37 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default foreach and query

Why would the below return

name1
name2

name1
name2
name3
name4

name1
name2
name3
name4
name5
name6

repeating the previous values over and over? I only want to do the same query for every valid key and return the values for that key only.

PHP Code:
 foreach($playerid1 as $playerkey1=>$playervalue1){
if (!empty(
$playervalue1)){
$getplayers1 $DB_site->query("SELECT * FROM cclpinternational_players WHERE id = $playerkey1");
while (
$getplayer1 $DB_site->fetch_array($getplayers1)){
$lname1=$getplayer1['lname'];
$fname1=$getplayer1['fname'];
eval(
'$players1 .= "' fetch_template('soccer_viewstatsplayer1') . '";');
}
}

Reply With Quote
  #2  
Old 01-20-2006, 09:41 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My god, PLEASE INDENT. I will honestly try to help you once you do so. It is completely, 100% impossible to read your code right now.
Reply With Quote
  #3  
Old 01-20-2006, 09:55 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry. Do not know what you mean by indent. Hope this is what you meant.


PHP Code:
$playerid1=unserialize($getname['preddata1']); 
foreach(
$playerid1 as $playerkey1=>$playervalue1)
{
if (!empty(
$playervalue1))
{
$getplayers1 $DB_site->query("SELECT * FROM cclpinternational_players WHERE id = $playerkey1");
while (
$getplayer1 $DB_site->fetch_array($getplayers1))
{
$lname1=$getplayer1['lname'];
$fname1=$getplayer1['fname'];
eval(
'$players1 .= "' fetch_template('soccer_viewstatsplayer1') . '";');
}
}

Reply With Quote
  #4  
Old 01-20-2006, 09:57 PM
Guest190829
Guest
 
Posts: n/a
Default

Here's what he means by indent:

PHP Code:
$playerid1=unserialize($getname['preddata1']); 
foreach(
$playerid1 as $playerkey1=>$playervalue1)
{
    if (!empty(
$playervalue1))
    {
        
$getplayers1 $DB_site->query("SELECT * FROM cclpinternational_players WHERE id = $playerkey1");
        
        while (
$getplayer1 $DB_site->fetch_array($getplayers1))
        {
            
$lname1=$getplayer1['lname'];
            
$fname1=$getplayer1['fname'];
            
            eval(
'$players1 .= "' fetch_template('soccer_viewstatsplayer1') . '";');
        }
    }

And for the solution it has to be the foreach loop that's causing that...
Reply With Quote
  #5  
Old 01-20-2006, 09:58 PM
peterska2 peterska2 is offline
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 6,504
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

indent - tab in

so text lokks like this (ok it's gobbledegook but you get the point)

Code:
boqscbuocdubocd
bjowcbisdvidvysi
bjocdbsdbdbsuibvius bocdbouvbouvbousbuosv bocdqboobdbodwvbouvfbou
ibhdbiwdvbubuivwbui bwcdbuowcdbucdwbuo owcdobwdvbo
obuwdvbuowvdbouvbwd bodbuowdbuovwdbou nwdvbovwboovwb
bdbuovbuovwfbou
obudbuovdobuvsdbuo
Reply With Quote
  #6  
Old 01-20-2006, 11:15 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Danny.VBT
And for the solution it has to be the foreach loop that's causing that...
thanks for indent lesson. The foreach loop is needed so I repeat that query for every key.
Reply With Quote
  #7  
Old 01-20-2006, 11:39 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Never query in a loop.
Reply With Quote
  #8  
Old 01-20-2006, 11:42 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok. Then how would I do that query for every key?

I am having the same problem with a non query
$minutes1 returns only one line in the eval.


PHP Code:
 //get minutes1
$playerid1=unserialize($getname['preddata1']);
foreach(
$playerid1 as $playerkey1=>$playervalue1)
{
if (!empty(
$playervalue1))
       {
$minutes1=$playervalue1;
        }

P.S. How do you guys tab in the editor? Nothing happens for me. I had to do spaces.
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 11:26 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.03760 seconds
  • Memory Usage 2,247KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (7)postbit_onlinestatus
  • (8)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_postinfo_query
  • fetch_postinfo
  • 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