The Web Design Resource List

init()) { echo "Well this sucks
\n"; exit; } if ($Delete == "Delete" && !empty($LinkID)) { // need to write delete function $sql = "DELETE FROM Links WHERE LinkID=$LinkID"; $isdeleted = $db->delete($sql); $sql2 = "DELETE FROM LinkCats WHERE LinkID=$LinkID"; $isdeleted2 = $db->delete($sql2); if ($isdeleted && $isdeleted2) { print << Link Deleted. EOF; } else { print << There was a problem deleting that link. EOF; } } if ($addlink == "Add Link") { $CatIDs = $HTTP_POST_VARS["CatIDs"]; $Url = $HTTP_POST_VARS["Url"]; $Description = $HTTP_POST_VARS["Description"]; $LinkName = $HTTP_POST_VARS["LinkName"]; $SubmitName = $HTTP_POST_VARS["SubmitName"]; $SubmitEmail = $HTTP_POST_VARS["SubmitEmail"]; $ExtraCats = $HTTP_POST_VARS["ExtraCats"]; $SubmitDate = $HTTP_POST_VARS["Date"]; $Approved = $HTTP_POST_VARS["Approved"]; $Important = $HTTP_POST_VARS["Important"]; if(!empty($Approved)) $Approved = 1; else $Approved = 0; if(!empty($Important)) $Important = 1; else $Important = 0; if(empty($Url)) { return false; } if(empty($LinkName)) { return false; } if(empty($SubmitName)) { $SubmitName = "Anonymous"; } if(empty($SubmitEmail)) { $SubmitEmail = "Not given"; } $CatIDarray = explode(" ",$CatIDs); $sql = "INSERT INTO Links "; $sql .= "(Url,LinkName,Description,SubmitName,SubmitEmail,SubmitDate,Approved,Important) "; $sql .= "values "; $sql .= "('$Url','$LinkName','$Description','$SubmitName','$SubmitEmail',$SubmitDate,$Approved,$Important) "; $results = $db->insert($sql); foreach ($CatIDarray as $thisID) { $sql2 = "INSERT INTO LinkCats "; $sql2 .= "(LinkID,CatID) "; $sql2 .= "values "; $sql2 .= "('$results','$thisID') "; $results2 = $db->insert($sql2); } if ($results) { print << New link added. EOF; } else { print << There was a problem adding that link. EOF; } } if ($editlink == "Update Link") { // try to update link here $CatIDs = $HTTP_POST_VARS["CatIDs"]; $Url = $HTTP_POST_VARS["Url"]; $Description = $HTTP_POST_VARS["Description"]; $LinkName = $HTTP_POST_VARS["LinkName"]; $SubmitName = $HTTP_POST_VARS["SubmitName"]; $SubmitEmail = $HTTP_POST_VARS["SubmitEmail"]; $ExtraCats = $HTTP_POST_VARS["ExtraCats"]; $SubmitDate = $HTTP_POST_VARS["Date"]; $Approved = $HTTP_POST_VARS["Approved"]; $Important = $HTTP_POST_VARS["Important"]; if(!empty($Approved)) $Approved = 1; else $Approved = 0; if(!empty($Important)) $Important = 1; else $Important = 0; if(empty($Url)) { return false; } if(empty($LinkName)) { return false; } if(empty($SubmitName)) { $SubmitName = "Anonymous"; } if(empty($SubmitEmail)) { $SubmitEmail = "Not given"; } $CatIDarray = explode(" ",$CatIDs); $sql = "UPDATE Links SET "; $sql .= "Url='$Url',LinkName='$LinkName',Description='$Description',SubmitName='$SubmitName',SubmitEmail='$SubmitEmail',SubmitDate=$SubmitDate,Approved=$Approved,Important=$Important "; $sql .= "WHERE LinkID=$LinkID"; $updated = $db->update($sql); // update the LinkCats table by deleted and recreating entries $sql2 = "DELETE FROM LinkCats WHERE LinkID=$LinkID"; $isdeleted2 = $db->delete($sql2); foreach ($CatIDarray as $thisID) { $sql3 = "INSERT INTO LinkCats "; $sql3 .= "(LinkID,CatID) "; $sql3 .= "values "; $sql3 .= "('$LinkID','$thisID') "; $results2 = $db->insert($sql3); } if ($updated) { print << Link updated. EOF; } else { print << There was a problem editing that link. EOF; } } ?>

Create a new link
Reload this page

select("SELECT * FROM Links")); if (empty($record) || $record < 1) $record = 1; $offset = $record - 1; $sql = "SELECT * FROM Links ORDER BY SubmitDate DESC LIMIT $offset,$max_per_page"; $results = $db->select($sql); $records_this_page = count($results); $this_page_first = $record; $this_page_last = $record + $records_this_page - 1; $next_page_first = $this_page_last + 1; $prev_page_first = $this_page_first - $max_per_page; if(!empty($results)) { print "

\n"; print "Links: (showing $this_page_first-$this_page_last of $total)\n"; print "

\n"; if ($records_this_page < $total) { print "

\n"; // print previous link if required if ($this_page_first > 1) print "previous "; // print numbered links to remaining pages for ($i=1;$i<=ceil($total/$max_per_page);$i++) { if ($record > ($i-1)*$max_per_page && $record <= $i*$max_per_page) { print "$i "; } else { $next = ($i-1)*$max_per_page+1; print "$i "; } } // print next link if required if ($this_page_last < $total) print "next"; print "

\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; $isodd = TRUE; while ( list ( $key,$val ) = each ($results)) { $LinkID = stripslashes($val["LinkID"]); $Url = stripslashes($val["Url"]); $LinkName = stripslashes($val["LinkName"]); $Description = stripslashes($val["Description"]); $SubmitDate = stripslashes($val["SubmitDate"]); $FormattedDate = date("d/m/y",$SubmitDate); if ($isodd) { $rowclass = "odd"; $isodd = FALSE; } else { $rowclass = "even"; $isodd = TRUE; } // truncate description to a certain maximum length $truncate = 40; if (strlen($Description) > $truncate) $ShortDesc = substr($Description, 0, $truncate) . "..."; else $ShortDesc = $Description; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } print "
TitleDescriptionDateOptions
$LinkName$ShortDesc$FormattedDatevisiteditdelete
\n"; if ($records_this_page < $total) { print "

\n"; // print previous link if required if ($this_page_first > 1) print "previous "; // print numbered links to remaining pages for ($i=1;$i<=ceil($total/$max_per_page);$i++) { if ($record > ($i-1)*$max_per_page && $record <= $i*$max_per_page) { print "$i "; } else { $next = ($i-1)*$max_per_page+1; print "$i "; } } // print next link if required if ($this_page_last < $total) print "next"; print "

\n"; } } else { print "No matches!"; } ?>