Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

How to code an SQL command

Quote Reply
How to code an SQL command
Hello!

I want to run a direct SQL command daily, and at first I thought I would set up a CRON job in conjunction with the daily build job... then I thought I might just put the SQL command right into nph-build.cgi

So...... how do I write a command in there to run an SQL command (or am I all wrong asbout doing this anyway???)

I want to run:

Update Links set Hits = '0' where CategoryID = 50

TIA!

Dave

Quote Reply
Re: How to code an SQL command In reply to
You could include that by using the built-in processes of prepare, execute, and do within Links SQL, like the following:

Code:

$LINKSDB->do ("UPDATE Links
SET Hits = '0'
WHERE CategoryID = 50");


You can stick these codes in whatever subroutine you want...of course, if you are logging the build process, then you would want to add print statements before and/or after the above codes.

Of course, the above codes may be tweaking...but at least I gave you an example of how this could be accomplished in the nph-build.cgi script.

BTW: Aren't you running your nph-build.cgi via Cron anyway???

Regards,

Eliot Lee

Quote Reply
Re: How to code an SQL command In reply to
Eliot!

Thank you so much! I will give that a shot.

Yes, I do use the cron job to run nph-build.cgi every morning at 2 AM... and I thought if I put this line in at the top, it would clear the hits on that category BEFORE it builds, thus showing the "What's Cool" EXCEPT for that category...

(To get WAY TOO in depth, but just so you know.... my site is all cartoons, but I did put bios in for Mickey Mouse, Bugs Bunny, etc... But I do not want them rated as "Top Cartoons" because they are not... just a teeny bit of "housecleaning!" Oh, and by the way, the Mickey bio is WAY MORE popular than any cartoon on our site...)

OK too much info, I know.... sorry!

Dave

Quote Reply
Re: How to code an SQL command In reply to
Eliot (and anyone else who this may help):

I took the basic syntax that Eliot supplied, and plopped that right into nph-build.cgi, and the script failed. So I played around, and found I had to supply a variable to make it work. The final code to get this to work as part of nph-build.cgi is:
[p]
In Reply To:
print "Zeroing Out Disney Character Hits Counters...\n\n";


$zero = $LINKDB->do (" UPDATE Links SET Hits = '0' WHERE CategoryID = '50' ");



print "Done...\n\n";
Thanks again for getting me started!

Dave

Quote Reply
Re: How to code an SQL command In reply to
Well....

Why not do what I did. Let people rate it, gather the stats, but in the nph-build.cgi, where it builds the ratings just alter the query:

AND CategoryID != '50'


So, whatever records are pulled, EXCLUDE any that have the category ID of 50.

That way, you can still give the files their popularity, but it will only show up on the Category and Detail pages, not on the Rate or Cool pages.

I've done this on many of my sites to still let people rank and evaluate the quality of links, but prevent them from getting top billing (maybe they are just a bit off color, or you don't want them featured...).



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ