vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   foreach and query (https://vborg.vbsupport.ru/showthread.php?t=105841)

Lionel 01-20-2006 08:37 PM

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') . '";');
}
}



filburt1 01-20-2006 09:41 PM

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.

Lionel 01-20-2006 09:55 PM

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') . '";');
}
}



Guest190829 01-20-2006 09:57 PM

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...

peterska2 01-20-2006 09:58 PM

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


Lionel 01-20-2006 11:15 PM

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.

filburt1 01-20-2006 11:39 PM

Never query in a loop.

Lionel 01-20-2006 11:42 PM

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.


All times are GMT. The time now is 01:20 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.01080 seconds
  • Memory Usage 1,747KB
  • 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
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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