Min computer er noget ustabil, og crasher lidt for meget :)
Meen her er det ...
Test evt. på
http://mora.adsl.dk/download.phpDatabase kilden...
<?
$connection = mysql_connect(\"localhost\",\"download\",\"download\") or die(\"<center><h2>Database down, sorry for the probs.<br></h2></center>\");
mysql_select_db(\"download\", $connection);
mysql_query(\"drop table kategorier\");
mysql_query(\"drop table underkategorier\");
mysql_query(\"drop table antaldownloads\");
mysql_query(\"create table kategorier(
id int not null auto_increment,
navn varchar(200),
primary key(id))\") or die(mysql_error());
mysql_query(\"create table underkategorier(
id int not null auto_increment,
katid int,
navn varchar(200),
primary key(id))\") or die(mysql_error());
mysql_query(\"create table antaldownloads(
id int not null auto_increment,
fil varchar(200),
antal int,
katid int,
descr varchar(255),
primary key(id))\") or die(mysql_error());
mysql_query(\"insert into kategorier (navn) values (\'test1\')\");
mysql_query(\"insert into kategorier (navn) values (\'test2\')\");
mysql_query(\"insert into kategorier (navn) values (\'test3\')\");
mysql_query(\"insert into underkategorier (navn, katid) values (\'under1\', 1)\");
mysql_query(\"insert into underkategorier (navn, katid) values (\'under2\', 2)\");
mysql_query(\"insert into underkategorier (navn, katid) values (\'under3\', 3)\");
mysql_query(\"insert into antaldownloads (fil, antal, katid, descr) values (\'a.zip\', 0, 1, \'beskrivelse af a\')\");
mysql_query(\"insert into antaldownloads (fil, antal, katid, descr) values (\'b.zip\', 0, 2, \'bbb\')\");
mysql_query(\"insert into antaldownloads (fil, antal, katid, descr) values (\'c.zip\', 0, 3, \'beskrivelse af c\')\");
?>
Kilden...
<?
$connection = mysql_connect(\"localhost\",\"download\",\"download\") or die(\"<center><h2>Database down, sorry for the probs.<br></h2></center>\");
mysql_select_db(\"download\", $connection);
if($download){
$res=mysql_query(\"select * from antaldownloads where id=\'$download\'\");
$res2=mysql_fetch_array($res);
$nyantal=$res2[antal]+1;
mysql_query(\"update antaldownloads set antal=\'$nyantal\' where id=\'$download\'\");
//header(\"Location: $res2[fil]\");
}
$result=mysql_query(\"select * from antaldownloads order by antal desc limit 1\");
$row=mysql_fetch_array($result);
$fil2=split(\"\\.\",$row[fil]);
echo \"<b>$fil2[0] er hentet flest gange. ($row[antal])</b>\";
echo \"<br><br>\";
echo \"<br><br><hr><b>Top 10</b><br><br>\";
$result=mysql_query(\"select * from antaldownloads order by antal desc limit 10\");
while($row=mysql_fetch_array($result)){
$fil2=split(\"\\.\",$row[fil]);
echo \"$fil2[0] ($row[antal])<br>\";
}
if($kat!=\"\"){
echo \"<a href=\\\"download.php\\\">Tilbage til oversigten</a><br><br>\";
if($subkat!=\"\"){
//sub kat valgt
$r=mysql_query(\"select navn from kategorier where id=\'$kat\'\");
$rr=mysql_fetch_array($r);
$r2=mysql_query(\"select navn from underkategorier where id=\'$subkat\'\");
$rr2=mysql_fetch_array($r2);
echo \"<center><h1>$rr[navn] - $rr2[navn]</h1><br><br></center>\";
$k=mysql_query(\"select id from antaldownloads where katid=\'$subkat\'\");
if(mysql_num_rows($k)==0){
echo \"Denne kategori er tom.\";
exit;
}
echo \"<table border=1>\";
$result=mysql_query(\"select * from antaldownloads where katid=\'$kat\' order by fil asc\");
while($row=mysql_fetch_array($result)){
$fil2=split(\"\\.\",$row[fil]);
echo \"<tr><td><a href=\\\"download.php?download=$row[id]&kat=$kat&subkat=$subkat\\\">$fil2[0]</a></td><td>$row[antal]</td><td>$row[descr]</td></tr>\";
}
echo \"</table>\";
}else{
//vis subkats
echo \"<br><br><br><center><b>Under-Kategorier</b><br>\";
$result=mysql_query(\"select * from underkategorier where katid=\'$kat\' order by navn asc\");
$num=mysql_num_rows($result);
if($num>0){
while($row=mysql_fetch_array($result)){
echo \"<a href=\\\"download.php?kat=$kat&subkat=$row[id]\\\">$row[navn]</a><br>\";
}
}else{
echo \"Der er ikke oprettet nogle under-kategorier\";
}
}
}else{
//Ingen kategori er valgt.
echo \"<br><br><br><center><b>Kategorier</b><br>\";
$result=mysql_query(\"select * from kategorier order by navn asc\");
$num=mysql_num_rows($result);
if($num>0){
while($row=mysql_fetch_array($result)){
echo \"<a href=\\\"download.php?kat=$row[id]\\\">$row[navn]</a><br>\";
}
}else{
echo \"Der er ikke oprettet nogle kategorier\";
}
}
?>