Welcome to Geeklog, Anonymous Friday, November 08 2024 @ 09:50 pm EST
Geeklog Forums
Static Page Hack
Status: offline
jdustin
Forum User
Newbie
Registered: 08/27/05
Posts: 1
Here's a little chunk of code that takes all the links from gl_links and outputs them into even length columns with category breaks. I like having a single page with lots of links. Maybe someone else can use the code.
$maxcols = 4; $colpercent = round(100 / $maxcols);
$rst = mysql_query("select count(lid) from gl_links");
$rec = mysql_fetch_array($rst, MYSQL_ASSOC); $qcnt = $rec["count(lid)"];
mysql_free_result($rst);
$rst = mysql_query("select count(distinct category) from gl_links");
$rec = mysql_fetch_array($rst, MYSQL_ASSOC); $ccnt = $rec["count(distinct category)"];
mysql_free_result($rst);
//Make the nominal column count evenly divisible by maxcols
if (($qcnt+$ccnt) % $maxcols > 0) {
$qcnt+=$maxcols-(($qcnt+$ccnt) % $maxcols);
}
$rst = mysql_query("select * from gl_links order by category, title");
echo "";
$i=round(($qcnt+$ccnt)/$maxcols)-1; $colcount=0; $lastcat="";
while ($rec = mysql_fetch_array($rst, MYSQL_ASSOC)) {
$cat = $rec['category'];
if($cat!=$lastcat) {
if($colcount
if($i>=round(($qcnt+$ccnt)/$maxcols)-1) {
echo ""; $i=0; $colcount+=1;
}
}
echo "<b>$cat</b><br>"; $i+=1; $lastcat = $cat;
}
if($colcount
if($i>=round(($qcnt+$ccnt)/$maxcols)) {
echo ""; $i=0; $colcount+=1;
}
}
$lid = $rec['lid']; $title = $rec['title']; $url = $rec['url'];
echo "<a href="$url">$title</a><br>"; $i+=1;
}
mysql_free_result($rst);
echo "";
Text Formatted Code
$maxcols = 4; $colpercent = round(100 / $maxcols);
$rst = mysql_query("select count(lid) from gl_links");
$rec = mysql_fetch_array($rst, MYSQL_ASSOC); $qcnt = $rec["count(lid)"];
mysql_free_result($rst);
$rst = mysql_query("select count(distinct category) from gl_links");
$rec = mysql_fetch_array($rst, MYSQL_ASSOC); $ccnt = $rec["count(distinct category)"];
mysql_free_result($rst);
//Make the nominal column count evenly divisible by maxcols
if (($qcnt+$ccnt) % $maxcols > 0) {
$qcnt+=$maxcols-(($qcnt+$ccnt) % $maxcols);
}
$rst = mysql_query("select * from gl_links order by category, title");
echo "";
$i=round(($qcnt+$ccnt)/$maxcols)-1; $colcount=0; $lastcat="";
while ($rec = mysql_fetch_array($rst, MYSQL_ASSOC)) {
$cat = $rec['category'];
if($cat!=$lastcat) {
if($colcount
if($i>=round(($qcnt+$ccnt)/$maxcols)-1) {
echo ""; $i=0; $colcount+=1;
}
}
echo "<b>$cat</b><br>"; $i+=1; $lastcat = $cat;
}
if($colcount
if($i>=round(($qcnt+$ccnt)/$maxcols)) {
echo ""; $i=0; $colcount+=1;
}
}
$lid = $rec['lid']; $title = $rec['title']; $url = $rec['url'];
echo "<a href="$url">$title</a><br>"; $i+=1;
}
mysql_free_result($rst);
echo "";
18
12
Quote
All times are EST. The time is now 09:50 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content