This is another going-back-to-square-one thread. With a lot of help, I hammered out a dynamic table query that seems to do what I want it to. The only catch is that it displays the data outside the table, and I can't figure out how to make it display IN the table.
I also have a second query that I think might work, also...
But, again, I can't make it display IN the table.PHP Code:/*
$res = mysql_query("SELECT Area, Class, `Order` FROM symbols ORDER BY `Order`");
while ($row = mysql_fetch_row($res))
$resultArray = array();
while($row = mysql_fetch_assoc($result)) {
$resultArray[$row['mammalorder']][] = $row['area'];
foreach(array_keys($resultArray) as $mammalorder) {
// example output
// echo implode(', ', $resultArray[$mammalorder]).' | ' $mammalorder;
}
*/
Can someone help me straighten this out once and for all? I pasted the entire source code below. It includes a lot of junk, but I left BIG spaces before the two most important sections - the query and the table rows.
Thanks!
PHP Code:<?php
switch ($Animals['SymClass']) {
case 'animals':
$colors = array( '#f4eec2', '' );
$n=0;
$size=count($colors);
break;
case 'plants':
$colors = array( '#80ff80', '', '#bfffbf', '' );
$n=0;
$size=count($colors);
break;
default:
break;
}
switch ($Animals['SymClass']) {
case 'animals':
$BG = '#900';
$n=0;
$size=count($colors);
break;
case 'plants':
$BG = '#090';
$n=0;
$size=count($colors);
break;
default:
break;
}
$res = mysql_query("SELECT DISTINCT(`Order`) FROM symbols WHERE Class = '$myname'");
$orderArray = array();
while ($row = mysql_fetch_row($res)) {
//Dump all the orders into an array
$orderArray[] = $row[0];
}
$placeArray = array();
for ($counter = 0; $counter < count($orderArray); $counter++) {
$res = mysql_query("SELECT Area FROM symbols WHERE `Order`='$orderArray[$counter]'");
$placeArrayForOrder = array();
while ($row = mysql_fetch_row($res)) {
//Dump all the places into an array
$placeArrayForOrder[] = $row[0];
}
$placeArray[] = $placeArrayForOrder;
}
for ($counter = 0; $counter < count($orderArray); $counter++) {
echo $orderArray[$counter] . ': ';
$tempArray = array();
$tempArray = $placeArray[$counter];
for ($counterI = 0; $counterI < count($tempArray); $counterI++) {
if ($counterI == 0)
echo $tempArray[$counterI];
else
echo ', ' . $tempArray[$counterI];
}
echo '<br>';
}
$block = "<table class=\"sortphp_ref\" id=\"Table2\" style=\"margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;\">";
$block .="<thead>
<tr><th style=\"background: #666; color: #fff;\">Places</th>
<th style=\"background: $BG; color: #fff;\">Orders</th></tr>
</thead>
<tbody>";
// Look at this as rows & columns of a table,
// the colors will alternate just like to do in this list.
switch ($Animals['SymClass']) {
case 'animals':
// INTERNAL SWITCH
switch ($Animals['ClassCommon']) {
case 'fishes':
$color_sets = array(
array('#eee', '#cff'),
array('',''),
);
break;
default:
$color_sets = array(
array('#eee', '#f4eec2'),
array('',''),
);
break;
}
// END INTERNAL SWITCH
break;
case 'plants':
$color_sets = array(
array('#eee', '#80ff80'),
array('',''),
array('#eee', '#bfffbf'),
array('',''),
);
break;
default:
break;
}
// Count colors, used to determine which color set to use.
$cset_size = sizeof($color_sets);
$i = 0;
while ($row = mysql_fetch_array ($res)) {
// Determine color set
$c = $i % $cset_size;
switch ($Animals['SymClass']) {
case 'animals':
$LinkSymbol = '/animals/' . strtolower($row["ClassCommon"]) . '/' . strtolower(substr($row["Order"],0,3)) . '/';
break;
case 'plants':
$LinkSymbol = '/plants/' . strtolower($row["ClassCommon"]) . '/' . strtolower(substr($row["Order"],0,3)) . '/';
break;
default:
break;
}
$block .= '<tr>';
$block .= '<td>' . $tempArray[$counter] . '</td>';
$block .= '<td>' . $tempArray['$counterI'] . '</td>';
$block .= '</tr>';
$i++;
}
$block .= "</tbody></table>";
echo $block;
?>






Bookmarks