Reputation: 3697
I'm very new to the idea of adding values to a database, so would like some advise on whether this is possible and how I would do it.
I have a code that counts the lines of code written in a project, the code has to be in the folder that it is counting the lines of code from however I want to display this number on my site elsewhere. My site is a wordpress one, so i thought of sending this number to the database and calling on it in a template file elsewhere.
Is there a way to send this number to my database and have it keep up to date in real-time so that I can call it from other places in my site?
My LOC script can be seen running here: http://www.skizzar.com/wp-content/loc.php
and the number is displayed using the command:
$folder -> count_lines()
update
I've added the following code to my loc.php
$num_of_lines = $folder -> count_lines();
add_option('line_count', $num_of_lines);
And called it in my theme files using
echo get_option('line_count', '0');
So far this just returns 0 as the value and causes a fatal error on loc.php "call to undefined function..."
Second update
Got the code to work by adding
require_once('wp-config.php');
To the top of my code, the issue now is that it doesn't update in real time - is there a way to do this?
Upvotes: 0
Views: 357
Reputation: 12860
Assuming you are saving the value to the database with wordpress as well, use add_option and get_option. Something like this:
add_option('line_count', $num_of_lines);
And in your template, display it with:
echo get_option('line_count', '0');
Upvotes: 1