function get_views($sql)
{
$res = mysql_query($sql) or die ("SQL Abfrage Fehler!");
$rows = array();
while($row = mysql_fetch_object($res))
{
$rows[] = $row;
}
return $rows;
}
$dbAbfrage = get_views("Select Rechnername, RAM, Grafikkarten, CPU, MHZ from Table");
for($i = 0; $i < count($dbAbfrage); $i++){
switch($sort){
case "Rechnername":
$sort2 = $dbAbfrage[$i]->Rechnername;
break;
case "RAM":
$sort2 = $dbAbfrage[$i]->RAM;
break;
case "Grafikkarten":
$sort2 = $dbAbfrage[$i]->Grafikkarten;
break;
case "CPU":
$sort2 = $dbAbfrage[$i]->CPU;
break;
case "MHZ":
$sort2 = $dbAbfrage[$i]->MHZ;
break;
}
$lines[] = array(
"id" => "00_".$sort2,
"Rechnername" => $dbAbfrage[$i]->Rechnername,
"RAM" => $dbAbfrage[$i]->RAM,
"Grafikkarten" => $dbAbfrage[$i]->Grafikkarten,
"CPU" => $dbAbfrage[$i]->CPU,
"MHZ" => $dbAbfrage[$i]->MHZ);
}
if($how_sort == "up"){
rsort($lines);
}else{
sort($lines);
}
?>
<table>
<?php
if($how_sort == "up"){
?>
<tr>
<td><a href='<? echo $_PHP_SELF."?sort=Rechnername&how_sort=down" ?>'>Rechnername <? if($sort == "Rechnername") { echo "v"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=RAM&how_sort=down" ?>'>RAM <? if($sort == "RAM") { echo "v"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=Grafikkarten&how_sort=down" ?>'>Grafikkarten <? if($sort == "Grafikkarten") { echo "v"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=CPU&how_sort=down" ?>'>CPU <? if($sort == "CPU") { echo "v"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=MHZ&how_sort=down" ?>'>MHZ <? if($sort == "MHZ") { echo "v"; } ?></a></td>
</tr>
<?php
}else{
?>
<tr>
<td><a href='<? echo $_PHP_SELF."?sort=Rechnername&how_sort=up" ?>'>Rechnername <? if($sort == "Rechnername") { echo "^"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=RAM&how_sort=up" ?>'>RAM <? if($sort == "RAM") { echo "^"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=Grafikkarten&how_sort=up" ?>'>Grafikkarten <? if($sort == "Grafikkarten") { echo "^"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=CPU&how_sort=up" ?>'>CPU <? if($sort == "CPU") { echo "^"; } ?></a></td>
<td><a href='<? echo $_PHP_SELF."?sort=MHZ&how_sort=up" ?>'>MHZ <? if($sort == "MHZ") { echo "^"; } ?></a></td>
</tr>
<?php
}
foreach ($lines as $key => $val) {
?>
<tr>
<td id='<? echo $val['id'] ?>'><? echo $val['Rechnername'] ?></td>
<td><? echo $val['RAM'] ?></td>
<td><? echo $val['Grafikkarten'] ?></td>
<td><? echo $val['CPU'] ?></td>
<td><? echo $val['MHZ'] ?></td>
</tr>
<?php
}
?>
</table>