Forum Moderators: coopster
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple", "c" => "peach", "b" => "pear",);
What I want is something like this.
d = lemon
a = orange
b = banana, pear
c = apple, peach
The arrays a bit more complecated than that though. Here's some of it
Array ( [0] => Array ( [Section] => District Office [0] => District Office [SectionID] => 2 [1] => 2 [StaffNumber] => 0555339 [2] => 0555339 [Forename] => somename [3] => J [Surname] => somename [4] => somename ) [1] => Array ( [Section] => District Office [0] => District Office [SectionID] => 4 [1] => 4 [StaffNumber] => 0570362 [2] => 0570362 [Forename] => somename [3] => somename [Surname] => somename [4] => somename )
[webmasterworld.com...]
select section, sectionid from table
select forname, surname, secitonid from table2
Then do something like this
if (!(strcmp($rslt['sectionid'], $rslt2["sectionid"]))){
do something
}
Would that work?
$array = array();
$query = (query statement)
while ($res = mysql_fetch_object($query)) {
$array["$res->letter"][$res->fruit] = "";
}
which would make each letter and actuall array
array would contain:
so you would have
$array[0] => a
$array[1] => b
$array[2] => c
$array[3] => d
so now if you do this
$fruit = $array[1]
each key in fruit is now one of the fruits for the key that corisponds to $array[1]
so then you would have:
$fruit[banana] => ""
$fruit[pear] => ""
banana could be green or yellow. If the first value is green then the next one is yellow would banana become yellow or would it be green and yellow. Am I making sense?
function build(){
$x = 0;
$rsSurname = "SELECT Section.SectionID, Section.Section, WorksPhone.StaffNumber, Forename, Surname
FROM Section INNER JOIN WorksPhone ON Section.[Section Code] = WorksPhone.[Section Code] WHERE Employee=-1
ORDER BY SectionID ASC";
$surname = new Get_Sql(); $surname_rslts = $surname->SqlLoop($rsSurname);
$surname_count = $surname->SqlCount($rsSurname);while ($x < $surname_count){
$a[] = $surname_rslts[$x++]['SectionID']; // Builds the array as $a
}
$b = array_unique($a);// Distinct number of Section id's
$b_count = count($b); // Counts values in array
$c = array_values($b); // Gets the values but also more importantly resets the array keys
function findkey($source, $searchkey){
$firsttimeround = true;
$secondtimeround = false;
reset($source);
while (list($key, $val) = each($source)) {
if (!(strcmp($searchkey, $val))){
// echo $key.'<br>';
$newindex[] = $key;
// print_r($newindex);
}
}
return $newindex;
}
for($i = 0; $i < $b_count ; $i++){
$find = findkey($a, $c[$i]); // test 79 for 79 there are 11 occurances
print_r($find); echo '<br>';
// return $find;
}
}
print_r(build());
It still needs refindment. I have to do some more tweeks. Like increasing $newindex key by 1 so it's not 0 and searching the original array "$surname_rslts" for the groupped results.
function build(){
$x = 0;
$rsSurname = "SELECT Section.SectionID, Section.Section, WorksPhone.StaffNumber, Forename, Surname
FROM Section INNER JOIN WorksPhone ON Section.[Section Code] = WorksPhone.[Section Code] WHERE Employee=-1
ORDER BY SectionID ASC";
$surname = new Get_Sql(); $surname_rslts = $surname->SqlLoop($rsSurname);
$surname_count = $surname->SqlCount($rsSurname);while ($x < $surname_count){
$a[] = $surname_rslts[$x++]['SectionID']; // Builds the array as $a
}
$b = array_unique($a);// Distinct number of Section id's
$b_count = count($b); // Counts values in array
$c = array_values($b); // Gets the values but also more importantly resets the array keys
function findkey($source, $searchkey){
reset($source);
while (list($key, $val) = each($source)) {
if (!(strcmp($searchkey, $val))){
$newindex[] = $key;
}
}
return $newindex;
}
for($i = 0; $i < $b_count ; $i++){ // Gathers all the keys from the original array
$find = findkey($a, $c[$i]); // Begins the search for the array keys
$find_count = count($find); // Counts how many values are in the array
for($z = 0; $z <= $find_count ; $z++){ // Finnally the finished result
print_r($surname_rslts[$find[$z]]);echo '<br>';
}
}
}
print_r(build());