Welcome to Geeklog, Anonymous Friday, December 27 2024 @ 12:08 am EST
Geeklog Forums
Need A Hack To Insert Number of Articles Into a Static Page
winnerdk
I have a static block on the top of my homepage that reads "There are currently more than 4,000 articles in our ever-expanding database..."
Is there any way that I can snatch the number of articles that are actually in the database so that it will appear in this line? That number is generated in the Admins Only block after "Stories" (4,026).
So, what's the snappy hack to have "There are currently (code) articles in our ever-expanding database..." ???
There would probably be all kinds of uses for this kind of a hack. Anyone have any ideas?
Don Winner, Panama-Guide.com
jmucchiello
$cnt = DB_getItem("SELECT COUNT(*) FROM {$_TABLES['stories']} WHERE draft = 0"
if you want to be fancy, throw in COM_getPermSQL('and'. And truly fancy COM_getTopicSQL(). You should look in lib-common.php at the COM_AdminMenu function for examples of generating the story counts.
winnerdk
In a static page? No problem. Add this code somewhere and then put the variable in your output: $cnt = DB_getItem("SELECT COUNT(*) FROM {$_TABLES['stories']} WHERE draft = 0"); if you want to be fancy, throw in COM_getPermSQL('and'). And truly fancy COM_getTopicSQL(). You should look in lib-common.php at the COM_AdminMenu function for examples of generating the story counts.
LWC
winnerdk, he meant obviously that you put it somewhere in your staticpage and then you can use
wherever you want in that staticpage.
Of course, you need to enable PHP in your staticpage and read how to use PHP in staticpages.
winnerdk
jmucchiello, please use the CODE tag as that's what it's for and also some things turn to smilies otherwise. winnerdk, he meant obviously that you put it somewhere in your staticpage and then you can use
winnerdk
Parse error: syntax error, unexpected '<' in /home/panamax/public_html/plugins/staticpages/functions.inc(841) : eval()'d code on line 1
This is what I'm trying, and it's not working;
<br /><p><b><a href="http://www.panama-guide.com/index.php">Panama Guide</a></b> is the #1 English Language web site about the Republic of Panama. There are currently echo $cnt; articles in our ever-expanding database and we update daily so check back often. About 3,000 people visit <a href="http://www.panama-guide.com/">Panama-Guide.com</a> every day to follow current events and to use the other resources available. We provide English language news about Panama as well as information about all of the other things you need to know if you plan to visit or live here. We focus on those topics and issues which are of greatest importance to the English speaking expatriate community. And if you can't <a href="http://www.panama-guide.com/search.php">find what you need to know</a>, we take <a href="http://www.panama-guide.com/article.php/20060921101146229">requests</a>. Welcome aboard, and tell your friends.
$cnt = DB_getItem("SELECT COUNT(*) FROM {$_TABLES['stories']} WHERE draft = 0"
winnerdk
1. php working in the static page.
2. working php before and after the html on the same page;
3. But there's obviously something wrong with the string of code I'm trying to use to get the number from the database;
4. I'm getting this error;
"An error has occurred:
2 - Missing argument 2 for db_getitem() @ /home/panamax/public_html/system/lib-database.php line 250"
5. This error is occuring as a result of this line:
$cnt = DB_getItem("SELECT COUNT(*) FROM {$_TABLES['stories']} WHERE draft = 0"
So, what can I change to get this to work?
Dirk
DB_query takes a complete SQL query as a string while DB_getItem expects three parameters from which it builds the SQL query by itself.
bye, Dirk
winnerdk
On the webpage: "An SQL error has occurred. Please see error.log for details."
And in the error log: "Sat 19 May 2007 13:54:17 EDT - 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 'WHERE draft = 0' at line 1. SQL in question: SELECT COUNT(*) FROM WHERE draft = 0 "
Dirk
global $_TABLES;
$result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW()");
list($count) = DB_fetchArray($result);
echo $count;
?> stories in our database!</p>
<?php
That's for the "execute PHP" mode.
bye, Dirk
winnerdk
Not the greatest piece of code and it doesn't check permissions:
global $_TABLES;
$result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW()");
list($count) = DB_fetchArray($result);
echo $count;
?> stories in our database!</p>
<?php
<p><b><a href="http://www.panama-guide.com/index.php">Panama Guide</a></b> is the #1 English Language web site about the Republic of Panama. There are currently
<?php
global $_TABLES;
$result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW()");
list($count) = DB_fetchArray($result);
echo $count;
?>
articles in our ever-expanding database and we update daily so check back often. About 3,000 people visit <a href="http://www.panama-guide.com/">Panama-Guide.com</a> every day to follow current events and to use the other resources available. We provide English language news about Panama as well as information about all of the other things you need to know if you plan to visit or live here. We focus on those topics and issues which are of greatest importance to the English speaking expatriate community. And if you can't <a href="http://www.panama-guide.com/search.php">find what you need to know</a>, we take <a href="http://www.panama-guide.com/article.php/20060921101146229">requests</a>. Welcome aboard, and tell your friends.
LWC
Yes, by using COM_numberFormat:
<p>
<?php
global $_TABLES;
if (COM_getLanguageId() == "he") {
$pre_number = "יש כרגע";
$post_number = "מ××ž×¨×™× ×‘×ž×גר ×©×œ× ×•!";
} else {
$pre_number = "There are currently";
$post_number = "stories in our database!";
}
$result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW()");
list($count) = DB_fetchArray($result);
echo $pre_number . ' ' . COM_numberFormat($count) . ' ' . $post_number;
?>
</p>
<?php
Also added multilingual support there. If you don't need it, just keep the latter $pre_number and $post_number (without the surrounding IF statement),
Dirk, I've also ready asked in the past (because it's needed for my RTL support patch, which lets one disable RTL in non multilingual LTR sites, such as this one), but why don't you add a simple config setting to enable or disable multilingual support?
winnerdk
- 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