Welcome to Geeklog Tuesday, July 14 2020 @ 10:42 pm EDT

Geeklog Forums

PHP links block


Status: offline

Euan

Forum User
Full Member
Registered: 22/04/02
Posts: 292
Here's a phpBlock to show the top links on the front page. I didn't find one of these anywhere else but I think I saw one somewhere once. Add the following to your system/lib-custom.php file: function phpblock_topLinks() { global $_TABLES, $_CONF, $LANG10; $result = DB_query("SELECT lid,url,title,hits from WHERE hits > 0 ORDER BY hits desc LIMIT 10"Wink; $nrows = DB_numRows($result); if ($nrows > 0) { for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); $retval .= '<a href="' . $_CONF['site_url'] . '/portal.php?url=' . $A['url'] . '&what=link&item=' . $A['lid'] . '">' . $A['title'] . '</a> (' . $A['hits'] . ')<br>'; } } else { $retval .= $LANG10[21]; } return $retval; } Then create a phpBlock to call the function. This is ripped from the stats.php file. Cheers, Euan.
-- Heather Engineering -- No job too small
 Quote

Status: offline

Kybla

Forum User
Newbie
Registered: 15/05/02
Posts: 9
The fifth line should be of course $result = DB_query("SELECT lid,url,title,hits from WHERE hits > 0 ORDER BY hits desc LIMIT 10"Wink; .. as in stats.php Smile
 Quote

Status: offline

Kybla

Forum User
Newbie
Registered: 15/05/02
Posts: 9
Well .. it's allright in preview, but then it disappears .. between "from" and "WHERE" should be written "($_TABLES['links'])", but instead of normal braces are curly braces.
 Quote

Anonymous

Anonymous
Oops. Didn't notice that. Thanks! Euan.
 Quote

Anonymous

Anonymous
Hopefully that will fix this error:
1064: You have an error in your SQL syntax near 'WHERE hits > 0 ORDER BY hits desc LIMIT 10' at line 1
 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 06/11/02
Posts: 523
I am getting this error in my error log

PHP Formatted Code

Tue May 18 20:20:53 2004 - 1064: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '> 0 ORDER BY hits desc LIMIT 10' at line 1. SQL in question: SELECT lid,url,title,hits from gl_linksWHERE hits > 0 ORDER BY hits desc LIMIT 10
 


This is the function I am using

PHP Formatted Code

function phpblock_topLinks()
{
global $_TABLES, $_CONF, $LANG10;

$retval .= "<p><table width="100%" border="0">n";
$retval .= "<tr><td><b>Site Name</b></td><td><b>Hits</b></td></tr>";
$result = DB_query("SELECT ID,SiteName,SiteURL,HitsOut from {$_TABLES['pllinks']} WHERE HitsOut > 0 ORDER BY HitsOut desc LIMIT 0, 10");
$nrows = DB_numRows($result);
if ($nrows > 0) {
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$retval .='<tr><td><a href="' . $_CONF['site_url'] . '/phplinks/out_frame.php?&ID=' . $A['ID'] . '">' . $A['SiteName'] . '';
$retval .='</a></td><td>' . $A['HitsOut'] . '</td></tr>';  
}
} else {
$retval .="<tr><td align="center">";   
$retval .= $LANG10[21];
$retval .="</td></tr>";
}
$retval .="</table><p>";
$retval .="<center>";
$retval .= '<a href="' . $_CONF['site_url'] . '/phplinks/index.php">More Links</a>';
$retval .="</center>";
return $retval;
}

 


 Quote

Status: offline

jmichael

Forum User
Chatty
Registered: 08/04/04
Posts: 47
Happens to me from time to time as well, there's a space missing between the table name and WHERE:

... from gl_linksWHERE hits ...
 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 06/11/02
Posts: 523
OK I am sure I am being a blind fool but where within

PHP Formatted Code

function phpblock_topLinks()
{
global $_TABLES, $_CONF, $LANG10;

$retval .= "<p><table width="100%" border="0">n";
$retval .= "<tr><td><b>Site Name</b></td><td><b>Hits</b></td></tr>";
$result = DB_query("SELECT ID,SiteName,SiteURL,HitsOut from {$_TABLES['pllinks']} WHERE HitsOut > 0 ORDER BY HitsOut desc LIMIT 0, 10");
$nrows = DB_numRows($result);
if ($nrows > 0) {
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$retval .='<tr><td><a href="' . $_CONF['site_url'] . '/phplinks/out_frame.php?&ID=' . $A['ID'] . '">' . $A['SiteName'] . '';
$retval .='</a></td><td>' . $A['HitsOut'] . '</td></tr>';  
}
} else {
$retval .="<tr><td align="center">";   
$retval .= $LANG10[21];
$retval .="</td></tr>";
}
$retval .="</table><p>";
$retval .="<center>";
$retval .= '<a href="' . $_CONF['site_url'] . '/phplinks/index.php">More Links</a>';
$retval .="</center>";
return $retval;
}


 


DO you see gl_linksWHERE cause I can not see it? If it is not here, where is it??

 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 06/11/02
Posts: 523
bump
 Quote

Status: offline

jmichael

Forum User
Chatty
Registered: 08/04/04
Posts: 47
doh, maybe I replied to the 'wrong' post? Can't see it either.
 Quote

Status: offline

ScurvyDawg

Forum User
Full Member
Registered: 06/11/02
Posts: 523
Yeah I have been unable to figure out where that syntax error lays. Oh well another block falls by the wayside.

I am going to try to get other things done and may come back to this another time.

 Quote

Status: offline

destr0yr

Forum User
Full Member
Registered: 06/07/02
Posts: 324
PHP Formatted Code

function phpblock_topLinks()
{
global $_TABLES, $_CONF, $LANG10;

$retval .= '<p><table width="100%" cellspacing="1" cellpadding="1" border="0">' . LB;
$retval .= '<tr><td><b>Site Name</b></td><td><b>Hits</b></td></tr>' . LB;
$sql = DB_query("SELECT ID,SiteName,SiteURL,HitsOut from {$_TABLES['pllinks']} WHERE HitsOut > 0 ORDER BY HitsOut desc LIMIT 0, 10");
$nrows = DB_numRows($sql);
if ($nrows > 0) {
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($sql);
$retval .= '<tr><td><a href="' . $_CONF['site_url'] . '/phplinks/out_frame.php?&ID=' . $A['ID'] . '">' . $A['SiteName'] . LB;
$retval .= '</a></td><td>' . $A['HitsOut'] . '</td></tr>' . LB;
}
} else {
$retval .= '<tr><td align="center">' . LB;
$retval .= $LANG10[21];
$retval .= '</td></tr>' . LB;
}
$retval .= '</table><p>' . LB;
$retval .= '<div align="center">' . LB;
$retval .= '<a href="' . $_CONF['site_url'] . '/phplinks/index.php">More Links</a>' . LB;
$retval .= '</div>' . LB;
return $retval;
}

 

this works for me.
-- destr0yr "I love deadlines. I like the whooshing sound they make as they fly by." -- Douglas Adams
 Quote

All times are EDT. The time is now 10:42 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