Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nest Array's ??

Status
Not open for further replies.

pookie62

Technical User
Oct 22, 2004
139
GB
Hi,
If I need fields from different tables and those have a relation in what I want to display, should I nest array's ?
Can one nest array's ?
Can someone provide a sample code how this works ?
I have such a complicated situation, is very hard to explain, tried on two ither Forums'without any replies so far... (see Please anyone, I really need help here !
Thanks !!!
 
Q: Can one nest array's ?
A: Yes.

Multi-dimensional arrays are a common thing in PHP and very useful.

Your first question I don't understand. However, if the data in different tables have relations then the (therefore so called) relational database engine could be the primary way to associate that data.
We need more info about what you are trying to do.
As for the arrays:
Code:
$myColors = array('blue','red','green');
$myTemp = array('very cold','cold','ok','hot','very hot');
$myArray = array($myColors, $myTemp);
echo("<pre>");
print_r($myArray);
echo("</pre>");
 
If its mysql based and relational, the mysql forum here really is very good, ( if you really must do it in PHP, DRJ478 really is very good :)

Either way, more info is required.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
i have read the cross reference on sitepoint. i think i can guess at what you were asking but i'm not certain.

what i would recommend is that you simplify your data structure and re-present your request on this forum or on mysql (i suspect that the issue is a mixture of the two - in which case perhaps try this forum first).
 
Thanks for your reply's !
The output that I want is displayed here:
and click "Alle Scores"
This is created manually and is very time consuming.
If all this could become dynamic would be great.
I know it's complicated and indeed a mixture of MySQL and PHP ignorance..
I have the feeling that I need more advanced code, like nested array's but have no experience writing them and don't know where to start..
Here's the script I have so far.
Please ask if you need more info..
Code:
<?php require_once('../../Connections/Nlprint.php'); ?>
<?php

mysql_select_db($database_Nlprint, $Nlprint);
//Selecting members from ASN
$query_deeln = "SELECT Id, deelnemer.Voornaam, deelnemer.Naam FROM deelnemer WHERE deelnemer.ASNNR >1";
$deeln = mysql_query($query_deeln, $Nlprint) or die(mysql_error());
while ($row = mysql_fetch_assoc($deeln))
{
   $ASNm[] = $row['Id'];
}

//Selecting all matches from current year
$sql="SELECT * FROM wedstrijd WHERE(Year(`Datum`) = 2005)ORDER BY datum";
$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
   $w_naam[] = $row['Naam'];
}

//Select one of four Categories (OKP,SKP,OKR,SKR)
$sqlKlasse = 'SELECT * FROM klasse';
$Kresult = mysql_query($sqlKlasse, $Nlprint) or die(mysql_error());
while ($row = mysql_fetch_assoc($Kresult))
{
   $Class[] = $row['Klasse'];
}

if (true === isset($_POST['Search']))
 {
    $where_clause = '';
    // handle search
    if (true === isset($_POST['Klasse']))
     $k_name = $_POST['Klasse'];
	   if (0 < strlen($k_name))
        {
          $where[] = ' Klasse = \'' . $k_name . '\'';
        }
		if (true === is_array($where))
        {
            $where_clause = implode(' AND ', $where);
        }
    }
$rhquery = "SELECT  klasse.Klasse,deelnemer.Naam AS Deelnemer,deelnemer.Voornaam AS Voornaam, wedstrijd.Naam AS Wedstrijd, truncate(score.punten ,2) AS Punten ,truncate(score.Tijd, 2) AS Tijd, truncate((score.punten / score.tijd),2) AS HitF FROM deelnemer inner join inschrijving on deelnemer.Id = inschrijving.DeelnemerId inner join wedstrijd on inschrijving.WedstrijdId = wedstrijd.Id inner join klasse on inschrijving.KlasseId = klasse.Id inner join score on inschrijving.Id = score.InschrijvingId inner join score as s2 on inschrijving.Id = s2.InschrijvingId where wedstrijd.Naam = ('PolderKolder 2005')AND klasse.Klasse = ('$k_name') GROUP BY klasse.Klasse, deelnemer.Voornaam, deelnemer.Naam, wedstrijd.Naam, truncate(score.Tijd ,2) HAVING Tijd = min(truncate(s2.Tijd,2)) ORDER BY klasse.Klasse, HitF desc";

$wedstrijdresult = mysql_query($rhquery) or die("Error: " . mysql_error());
$row_count = 2; 

// Dropdown
  $html_form = '<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">';
  $html_form .= '<br /><br ><strong>Selecteer de Klasse <br /></strong>';
  $html_form .= '<select name="Klasse">';
  $html_form .= '<option selected value="">Klasse</option>';
  foreach ($Class as $k_name)
  if($k_name == $_POST['Klasse']){ 
  $html_form .= "<option value=\"$k_name\" selected=\"selected\">" . $k_name . "</option>"; 
    } 
    else{ 
        $html_form .= "<option value=\"$k_name\">" . $k_name . "</option>"; 
    } 
  $html_form .= '</select> ';
  $html_form .= '<input type="submit" name="Search" value="Bekijk" />';
  $html_form .= '</form></>';

// build table for outputting match names 
   $html = '<table border="1">'; 
   $html .= '<tr>';
   $Ent='&nbsp';
   $html .= '<td border="1" width ="190">'. $Ent .'</td>'; 
   foreach ($w_naam as $w_name)
   {
    $html .= '<td border="1" width ="190">' . $w_name . '</td>'; 
	}
   while ($line = mysql_fetch_array($wedstrijdresult, MYSQL_ASSOC))
   {
	$row_count = $row_count;
	$perc = $line["HitF"]; 
    if (!isset($base)) { 
       $base = $perc; // set base to the score of this user    
	   }
	$Tempperc = ($perc / $base)*100;
	$Totperc = round($Tempperc, 3);
	$f_name = $line["Voornaam"];
	$l_name = $line["Deelnemer"];
	$sco = $line["Tijd"];
	$html .= '<tr border="1">';
	$html .= '<td width="190">'. $f_name ." ". $l_name .'</td>';
    $html .= '<td border="1">'. $Totperc .''."%".' </td>';
	//$html .= '<td border="1">'. $sco .'</td>';
	}
	$html .= '</tr>';
    $html .= '</table>'; 
  
// display results 
   echo $html_form;
   echo $html; 

mysql_free_result($deeln);
?>
 
What tables and structures do you have, and what items are relative?



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi KarveR,
These are the relevant tables and their structure.
You'll see the relative fields, I think..
Thanks for taking helping !


=deelnemer=
Id bigint(20) Nee
Naam varchar(255) Ja NULL
Voornaam varchar(255) Ja NULL
ASNNR bigint(20) Ja NULL
Datum_lid datetime Ja NULL
URL varchar(255) Ja NULL
Vereniging varchar(255) Ja NULL
Adres varchar(255) Ja NULL
Postcode varchar(255) Ja NULL
Woonplaats varchar(255) Ja NULL
Telnr varchar(255) Ja NULL
Email varchar(255) Ja NULL
Oud_Sefnr varchar(255) Ja NULL

=klasse=
Veld Type Null Standaardwaarde
Id bigint(20) Ja NULL
Klasse varchar(50) Ja NULL

=score=
Veld Type Null Standaardwaarde
Id bigint(20) Ja NULL
InschrijvingId bigint(20) Ja NULL
SerieNr smallint(6) Ja NULL
Tijd decimal(10,2) Nee 999.00
Punten smallint(6) Ja NULL

=inschrijving=
Veld Type Null Standaardwaarde
Id bigint(20) Ja NULL
DeelnemerId bigint(20) Ja NULL
WedstrijdId bigint(20) Ja NULL
KlasseId bigint(20) Ja NULL
Dag char(2) Ja NULL
Uur bigint(20) Ja NULL

=wedstrijd=
Veld Type Null Standaardwaarde
Id bigint(20) Nee 0
Naam varchar(50) Ja NULL
Datum datetime Ja NULL
Plaats varchar(50) Ja NULL

=klassement=
Veld Type Null Standaardwaarde
KlasseId bigint(20) Ja NULL
LevelId char(1) Ja NULL
DeelnemerId bigint(20) Ja NULL
Tot_percentage decimal(4,3) Ja NULL
Gem_percentage decimal(4,3) Ja NULL
 
Looking at the referenced page and your queries (and bear in mind I don't understand your language :)) it appears as

each persons score in % for each event in a class for a given year?

is this it or is there anything I've missed?


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I'm impressed !!
And this score in % (relative to the winner(=100%)of the event)is what I would like to display for each event.
Did you check ?
First column could also be static, just listing all members(they have an ASNNR >0 in table deelnemer)when they compete in the selected Klasse.
Perhaps making it easier ?
Can't say how greatfull I am that finally somebody is willing to help me..! Thanks very much again.!! and again
:))
 
I'm back from hols, need to catch up with work before I can play. Havent forgotten this tho .

k/.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top