Hi,
My script is supposed to step through my data sets and
create new data groups.
The data is in this style:
Set 1: {A_one|A_two|A_three|A_four|A_five}
Set 2: {B_one|B_two}
…
etc.
What I my script needs to do is select the [B]first data element[B]second data element
So each set continues outputting sequentially and on ending returns to beginning until the desired number of groups are created..
In this case I have set the number of groups to [B]10
My output is:
Notice: Undefined offset: 5 in /home/com567b/public_html/auto_change.php on line 35 Notice: Undefined offset: 6 in /home/com567b/public_html/auto_change.php on line 35
Created New Group: 1
A_one B-two C-three D-four E-five H-eight
Notice: Undefined offset: 5 in /home/com567b/public_html/auto_change.php on line 35 Notice: Undefined offset: 6 in /home/com567b/public_html/auto_change.php on line 35
Created New Group: 2
A_one B-two C-three D-four E-five H-eight
etc … up to New Group: 10
The new groups are all the same.
I am having problems incrementing the counter
and taking it back to the beginning. ?
Any help much appreciated. ๐ฎ
[B]This is my script:
( It includes test data )
[code=php]<?php
ini_set (“display_errors”, “1”);
error_reporting(E_ALL);
set_time_limit(10);
function inStr($needle, $haystack){
return @strpos($haystack, $needle) !== false;
}
function str_replaceFirst($s,$r,$str){
$l = strlen($str);
$a = strpos($str,$s);
$b = $a + strlen($s);
$temp = substr($str,0,$a) . $r . substr($str,$b,($l-$b));
return $temp;
}
function sqn_select($pass){
$mytext = $pass;
$idx = 0;
while(inStr(“}”,$mytext)){
$rbracket = strpos($mytext,”}”,0);
$tString = substr($mytext,0,$rbracket);
$tStringToken = explode(“{“,$tString);
$tStringCount = count($tStringToken) – 1;
$tString = $tStringToken[$tStringCount];
$tStringToken = explode(“|”,$tString);
$tStringCount = count($tStringToken) – 1;
$replace = $tStringToken[$idx++];
$tString = “{“.$tString.”}”;
$mytext = str_replaceFirst($tString,$replace,$mytext);
}
return $mytext;
}
$groups = 10;
$Db_data =”
{A_one|A_two|A_three|A_four|A_five}
{B-one|B-two|B-three|B-four|B-five|B-six|B-seven|B-eight|B-nine|B-ten|B-eleven|B-twelve}
{C-one|C-two|C-three}
{D-one|D-two|D-three|D-four|D-five|D-six|D-seven}
{E-one|E-two|E-three|E-four|E-five|E-six|E-seven|E-eight|E-nine|E-ten}
{F-one|F-two|F-three|F-four}
{G-one|G-two}
{H-one|H-two|H-three|H-four|H-five|H-six|H-seven|H-eight|H-nine}
“;
for ($grp= 1; $grp<= $groups ; $grp++) {
$Db_data = str_replace(“‘”,”`”,$Db_data);
$new_group = sqn_select($Db_data);
$new_group = str_replace(chr(13).chr(10),”<br />”.chr(13).chr(10),$new_group);
$wordCount = explode(” “,$new_group);
$wordCount = count($wordCount);
echo “<br>Created New Group: $grp<br>$new_group<br><br>”;
} // end for
echo “<br><b>Total $grp New Groups created</b><br>”;
?>
My desired output from the included test data is:
A_one B-one C-one D-one E-one F-one G-one H-one
A_two B-two C-two D-two E-two F-two G-two H-two
A_three B-three C-three D-three E-three F-three G-one H-three —> notice G goes back to one because there are only 2 elements
A_four B-four C-one D-four E-four F-four G-two H-four —> notice C goes back to one because there are only 3 elements
A_five B-five C-two D-five E-five F-one G-one H-five
A_one B-six C-three D-six E-six F-two G-two H-six —> notice A goes back to one because there are only 5 elements
A_two B-seven C-one D-seven E-seven F-three G-one H-seven
A_three B-eight C-two D-one E-eight F-four G-two H-eight
A_four B-nine C-three D-two E-nine F-one G-one H-nine
A_five B-ten C-one D-three E-ten F-two G-two H-one
Thanks for any help ?
.