Jump to content

Repeating array... Not supposed to


DBookatay

Recommended Posts

For some reason this array keeps repeating the 1st line onto the 2nd line and the 1st and 2nd line onto the 3rd line, and so on and so on.

 

unset ($grade); $grade = array();
  foreach ($row as $grade => $value) {
  if (substr($grade, 0,1)== "y") {
  if ($grade == "y1") {if ($value == "x") {$grades[] = "1";}}
  if ($grade == "y2") {if ($value == "x") {$grades[] = "2";}}
  if ($grade == "y3") {if ($value == "x") {$grades[] = "3";}}
  if ($grade == "y4") {if ($value == "x") {$grades[] = "4";}}
  if ($grade == "y5") {if ($value == "x") {$grades[] = "5";}}
  if ($grade == "y6") {if ($value == "x") {$grades[] = "6";}}
  if ($grade == "y7") {if ($value == "x") {$grades[] = "7";}}
  }
}
$grades_string = implode(", ", $grades);

 

The dB rows are titled y1, y2 etc.

 

I can show someone a link with the example of what I mean the error is if need be.

Link to comment
Share on other sites

For some reason this array keeps repeating the 1st line onto the 2nd line and the 1st and 2nd line onto the 3rd line, and so on and so on.

 

unset ($grade); $grade = array();
foreach ($row as $grade => $value) {
 if (substr($grade, 0,1)== "y") {
 if ($grade == "y1") {if ($value == "x") {$grades[] = "1";}}
 if ($grade == "y2") {if ($value == "x") {$grades[] = "2";}}
 if ($grade == "y3") {if ($value == "x") {$grades[] = "3";}}
 if ($grade == "y4") {if ($value == "x") {$grades[] = "4";}}
 if ($grade == "y5") {if ($value == "x") {$grades[] = "5";}}
 if ($grade == "y6") {if ($value == "x") {$grades[] = "6";}}
 if ($grade == "y7") {if ($value == "x") {$grades[] = "7";}}
}
}
$grades_string = implode(", ", $grades);

 

The dB rows are titled y1, y2 etc.

 

I can show someone a link with the example of what I mean the error is if need be.

 

 

Rewrote it, problem was it should of been unset ($grade); $grades = array();

unset ($grade); $grades = array();
  foreach ($row as $grade => $value) {
  if (substr($grade, 0,1)== "y" && $value == "x") {
  if ($grade == "y1") {$grades[] = "1";}
  if ($grade == "y2") {$grades[] = "2";}
  if ($grade == "y3") {$grades[] = "3";}
  if ($grade == "y4") {$grades[] = "4";}
  if ($grade == "y5") {$grades[] = "5";}
  if ($grade == "y6") {$grades[] = "6";}
  if ($grade == "y7") {$grades[] = "7";}
  }
}
$grades_string = implode(", ", $grades);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.