0

Im using the following function.

function GetSubmissions($coach){
     $result = mysql_query("SELECT * FROM `ptable` WHERE coach = '$_SESSION[username]'") or trigger_error(mysql_error()); 
     while($row = mysql_fetch_array($result)){ 
     foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 
      $id = $row['id'];
      $teampre = $row['team'];
      $eventpre = $row['event'];
      $statuspre = $row['status'];
      $eventarray = DecodeEvent($eventpre);
       $event = $eventarray[0];
       $cat = $eventarray[1];
       $subcat = $eventarray[2];
       $division = $eventarray[3];
       $type = $eventarray[4];
      $teamarray = DecodeTeam($teampre);
        foreach ($teamarray AS $key => $value){
         $teamgo .= $value[1]." ".$value[2]."<br/>";
       } 
      $push .= "<div id=submission><div id=event>$event</div><div id=status>$statuspre</div><div id=subinfo>$cat $subcat $division $type</div><div id=team>$teamgo</div></div>";
     }   

  return $push;
 }

What is happening, is that the $teampre contains a series of numbers representing the team members, which i pass to the DecodeTeam function to return the names of the given members in an array. The problem is. That say there are 3 results for the main query. The first is fine. The second result starts off with the team members from the first result. The third result starts off with the team members from the first and second queries, like a snowball effect.

I figure the problem is in the way im handling the $teamgo variable, but im not sure how to get the results to stop snowballing like this.

1
  • Can you also include code for DecodeTeam? Commented Oct 15, 2009 at 17:29

2 Answers 2

2

Looks like you just need to reset the $teamgo string each time you go through the loop:

$teamarray = DecodeTeam($teampre);
$teamgo = ""; // Reset so it doesn't contain the results from the last row.
foreach ($teamarray AS $key => $value){
   $teamgo .= $value[1]." ".$value[2]."<br/>";
} 
Sign up to request clarification or add additional context in comments.

1 Comment

If there was a high five button, i would have clicked that too! Thanks so much!
1

I was beat to the bunch but I beautified your code =)

function GetSubmissions($coach) {

  $result = mysql_query("SELECT * FROM `ptable` WHERE coach = '$_SESSION[username]'");

  while ($row = mysql_fetch_array($result)) { 

    // stripslashes
    foreach($row AS $key => $value) { 
      $row[$key] = stripslashes($value); 
    } 

    $id         = $row['id'];
    $teampre    = $row['team'];
    $eventpre   = $row['event'];
    $statuspre  = $row['status'];

    $eventarray = DecodeEvent($eventpre);
    $event      = $eventarray[0];
    $cat        = $eventarray[1];
    $subcat     = $eventarray[2];
    $division   = $eventarray[3];
    $type       = $eventarray[4];

    $teamarray  = DecodeTeam($teampre);
    $teamgo     = '';
    foreach ($teamarray AS $key => $value) {
      $teamgo .= $value[1]." ".$value[2]."<br/>";
    } 

    $push .= "blah blah blah";

  }   

  return $push;

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.