Opgradering af PHP script
Hej,Jeg har overtaget en side som jeg gerne vil have udviklet lidt på.
Jeg vil gerne have kategorier bygget ind i den, således at kategorierne vises i eksempelvis 3 kolonner og x rækker.
Her vises 3 kolonner og 1 række. Antal links i hver kategori vises i parantesen.
Kat. 1 (25) Kat. 2 (37) Kat. 3 (14)
Link 1 Link 1 Link 1
Link 2 Link 2 Link 2
Link 3 Link 3 Link 3
Link 4 Link 4 Link 4
Link 5 Link 5 Link 5
-----------
På siden "Tilføj URL" vil jeg gerne have karakter til at virke, således at jeg kan angive en karakter fra 1-5 for det link jeg tilføjer.
-----------
Jeg vil også gerne ha skrevet de inkluderede filer ind i selve index.php så systemet ikke skal hente filer rundt omkring på serveren.
-----------
Nogen hos jer der har mod på denne opgave, og hvad skal det evt. koste??
MySQL
Jeg er ikke sikker på at SQL er sat rigtigt op, så rettelser er velkomne.
CREATE TABLE `links` (
`id` int(11) NOT NULL auto_increment,
`top` tinyint(2) NOT NULL default '0',
`rating` int(2) default '0',
`hits` int(11) default '0',
`date` date default NULL,
`cat` varchar(64) NOT NULL default '',
`title` varchar(64) NOT NULL default '',
`url` varchar(256) NOT NULL default '',
UNIQUE KEY `id` (`id`),
KEY `top` (`top`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
INDEX.PHP
<?php
$page_title = "Linksamling";
$stylesheet = "blue";
require($_SERVER["DOCUMENT_ROOT"].'/php/boot.php');
include($_SERVER["DOCUMENT_ROOT"].'/php/functions.php');
?>
<table width="800" border="0">
<tr>
<td>
<?php
$thisfile = $PHP_SELF;
// linkstrenge til de tre funktioner.
$linkshowtop = "[ <a href=\"$thisfile\">Top links</a> ] ";
$linkshowall = "[ <a href=\"$thisfile?show=all\">Vis alle</a> ] ";
$linkadd = "[ <a href=\"$thisfile?addurl=yes\">Tilføj webside / URL</a> ] ";
if (strtolower($show) == "all") {
$where = "";
} else {
$where = " having point >= 0";
}
$count = query("select sum(hits) as cnt from links");
$hitcount = $count[0]->cnt;
/*
$result = query("select id,title,date,rating,hits,url,(hits*rating-(to_days(curdate())-to_days(date))) as point ".
"from links$where order by top desc, point DESC");
*/
$result = query("select id,title,date,rating,hits,url,(rating*10+(hits)) as point ".
"from links$where order by top desc, point DESC");
page_start("");
echo $linkshowtop;
echo $linkshowall;
echo $linkadd;
if (!isset($addurl)) {
echo "<table width='800' border=0 cellpadding=2 cellspacing=0>\n";
for ($i=0;$i<sizeof($result);$i++) {
if ($result[$i]->point >= 0) {
$point = $result[$i]->point;
} else {
$point = "-";
}
echo "<tr><td><p title='".$result[$i]->url."'>".
"<a href='/links/golink.php?id=".$result[$i]->id."' target='_blank'>".
stripslashes($result[$i]->title)."</a><a href='".$result[$i]->url."'>".
"</a></td>".
"<td><img src=\"/images/links/".$result[$i]->rating.".gif\" ".
"alt='".stars($result[$i]->rating)."' width='33' height='16'></td>".
"<td align=\"right\">".$result[$i]->hits."</td>";
echo "<td align=\"right\">$point</td>";
echo "</tr>\n";
}
echo "</table>";
} else {
?>
<form action='/links/addlink.php' method='post' target='_blank'>
<table width='600' border='0' align='center'>
<tr>
<td>Websidens navn: </td>
<td><input type='text' name='title' value='' size='30' id='t350'></td>
</tr>
<tr>
<td>URL : </td>
<td><input type='text' name='url' value='http://' size='30' id='t350'></td>
</tr>
<tr>
<td>Karakter : </td>
<td>
<label><input type="radio" name="Rating" value="1" id="Rating_0" />1</label>
<label><input type="radio" name="Rating" value="2" id="Rating_1" />2</label>
<label><input type="radio" name="Rating" value="3" id="Rating_2" />3</label>
<label><input type="radio" name="Rating" value="4" id="Rating_2" />4</label>
<label><input type="radio" name="Rating" value="5" id="Rating_2" />5</label>
</td>
</tr>
<tr>
<td colspan="2" align='center'><br /><input type='submit' value='Tilføj link' id='submit' name="submit"></td>
</tr>
<tr>
<td colspan="2" align='right'><br /><b>NB!</b> Din IP logges ved "Tilføj link"</td>
</tr>
</table>
</form>
<?}
echo "Total hits : $hitcount\n";
echo mysql_error();
page_end();
?>
</td>
</tr>
</table>
BOOT.PHP
<?php
$DB_HOST="localhost";
$DB_USER="";
$DB_PASS="";
$DB_DATABASE="";
if ($BOOT_PHP != 1) {
function query($string) {
global $DB_CONNECTION;
global $DB_DATABASE;
global $DB_USER;
global $DB_PASS;
global $DB_HOST;
if (!$DB_CONNECTION)
$DB_CONNECTION=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
$sqlresult=mysql_db_query($DB_DATABASE,$string,$DB_CONNECTION);
if (!$sqlresult) {
return array();
}
while ($row=mysql_fetch_object($sqlresult)) {
$result[]=$row;
}
return $result;
}
function squery($string) {
global $DB_CONNECTION;
global $DB_DATABASE;
global $DB_USER;
global $DB_PASS;
global $DB_HOST;
if (!$DB_CONNECTION)
$DB_CONNECTION=mysql_pconnect($DB_HOST,$DB_USER,$DB_PASS);
$sqlresult=mysql_db_query($DB_DATABASE,$string,$DB_CONNECTION);
}
function mappath() {
/* Credits to Beast for helping me with this one */
global $HTTP_HOST;
global $PHP_SELF;
return "http://" . $HTTP_HOST. dirname($PHP_SELF)."/";
}
$BOOT_PHP = 1;
}
?>
FUNCTIONS.PHP
<?
function stars($count) {
if ($count > 0) {
return "[".str_repeat("+",$count).str_repeat("-",10-$count)."]";
} else {
return "Afventer...";
}
}
function line($width=380) {
$temp = "<table cellpadding=0 cellspacing=2 border=0 width=$width height=1>".
"<tr><td bgcolor=#0000cf height=1 width=$width>".
"<img src=\"/rate/cleardot.gif\" alt=\"----------------------\" width=1 height=1></td></tr></table>\n";
return $temp;
}
function page_start() {
echo "<center><p><b>$title</b></p>\n";
}
function page_end() {
echo "</center>\n";
}
?>
Hilsen Frank