Page 1 of 1

nested region - losing display order

Posted: Mon May 19, 2003 5:47 am
by jarow
I have a nested region that is giving me a giving me one glitch.

This is what I am getting when I display the results:

Phylum
.......Clase1
..............Order1
.....................Family1
..............................Species 1
..............................Species 2
.......Clase2
.............Family2
....................Species3


Because there was NO (animal) Order in the db for Species 3 it changed the display order.

I need it to read as follows where even though there is no value for Order it still retains the positions of the earlier species:

Phylum
.......Clase1
..............Order1
.....................Family1
..............................Species 1
..............................Species 2
.......Clase2
.....................Family2
..............................Species3


Below is the query I am using and following that the nested region statements

Code: Select all

<? $base_phylum = ''; 
$base_clase = ''; 
$base_orden = ''; 
$base_familia = ''; 
$varphylum_rsspecies = "1";
if (isset($HTTP_GET_VARS['phylum'])) {
  $varphylum_rsspecies = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['phylum'] : addslashes($HTTP_GET_VARS['phylum']);
}
$varclase_rsspecies = "1";
if (isset($HTTP_GET_VARS['clase'])) {
  $varclase_rsspecies = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['clase'] : addslashes($HTTP_GET_VARS['clase']);
}
$varord_rsspecies = "1";
if (isset($HTTP_GET_VARS['orden'])) {
  $varord_rsspecies = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['orden'] : addslashes($HTTP_GET_VARS['orden']);
}
$varfam_rsspecies = "1";
if (isset($HTTP_GET_VARS['familia'])) {
  $varfam_rsspecies = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['familia'] : addslashes($HTTP_GET_VARS['familia']);
}
$vartax_rsspecies = "1";
if (isset($HTTP_GET_VARS['especie'])) {
  $vartax_rsspecies = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['especie'] : addslashes($HTTP_GET_VARS['especie']);
}
mysql_select_db($database_connFauna, $connFauna);
$query_rsspecies = sprintf("SELECT * FROM fauna WHERE phylum LIKE '%%%s%%' AND clase LIKE '%%%s%%' AND orden LIKE '%%%s%%' AND familia LIKE '%%%s%%' AND especie LIKE '%%%s%%' AND ('%s'!='' OR '%s'!='' OR '%s'!='' OR '%s'!='' OR '%s'!='') ORDER BY phylum, clase, orden, familia, especie ASC", $varphylum_rsspecies,$varclase_rsspecies,$varord_rsspecies,$varfam_rsspecies,$vartax_rsspecies,$varclase_rsspecies,$varphylum_rsspecies,$varord_rsspecies,$varfam_rsspecies,$vartax_rsspecies);
$rsspecies = mysql_query($query_rsspecies, $connFauna) or die(mysql_error());
$totalRows_rsspecies = mysql_num_rows($rsspecies);?>


and the nested region statements:

Code: Select all

<?while($row_rsspecies = mysql_fetch_assoc($rsspecies)) 
{
$i=0; //used to now how much space you need. 
// assumes $row_rsspecies['clase'] / $row_rsspecies['orden'] etc 
if($row_rsspecies['phylum']) {
   if($base_phylum != $row_rsspecies['phylum']) { 
      echo str_repeat("<dd>",$i++).'Phylum'. " ". $row_rsspecies['phylum']; 
      $base_phylum = $row_rsspecies['phylum']; 
   } else {
      $i++;
   }
} else {
   $base_phylum = '';
}
if($row_rsspecies['clase']) {
   if($base_clase != $row_rsspecies['clase']) { 
      echo str_repeat("<dd>",$i++).'Clas'. " " .$row_rsspecies['clase']; 
      $base_clase = $row_rsspecies['clase']; 
   } else {
      $i++;
   }
} else {
   $base_clase = '';
}
if($row_rsspecies['orden']) {
   if($base_orden != $row_rsspecies['orden']) { 
      echo str_repeat("<dd>",$i++).'Ord'. " " .$row_rsspecies['orden']; 
      $base_orden = $row_rsspecies['orden']; 
   } else {
      $i++;
   }
} else {
   $base_orden = '';
}

if($row_rsspecies['familia']) {
   if($base_familia != $row_rsspecies['familia']) { 
      echo str_repeat("<dd>",$i++).'Fam'. " " .$row_rsspecies['familia']; 
      $base_familia = $row_rsspecies['familia']; 
   } else {
      $i++;
   }
} else {
   $base_familia = '';
}
echo str_repeat("<dd>",$i++).$row_rsspecies['especie'].'<br />'; 
}?>



Any help on this would be greatly appreciated.....


Jarow

Posted: Mon May 19, 2003 10:53 am
by McGruff
A quick and possibly inadequate answer is to give every new species record a default Order value - adjust the database with a default value of 'none' in the Order field.

Now, when a new record is added with no Order specified, it's automatically set to "none".

Posted: Mon May 19, 2003 4:21 pm
by volka
if you nest the lists it becomes easier to maintain the layout even if there are some captions missing, e.g.

Code: Select all

<html>
	<head>
		<style>
			dl &#123; border-left: 1px dotted black &#125;
		</style>
	</head>
<body>
	<dl><dt>Phylum</dt>
		<dd>Chelicerata
			<dl><dt>Clas.<dt>
				<dd>Pycnogonida
					<dl><dt>Ord.</dt>
						<dd>
							<dl><dt>Fam.</dt>
								<dd>text</dd>
							</dl>
						</dd>
					</dl>
				</dd>
			</dl>
		</dd>
	</dl>
</body></html>