View Full Version : printing the contents of a variable
ok, i have a variable in the index.php file, what do i have to do to print it on the index page?
ericgtr
05-10-2005, 09:23 PM
You will need to add it to your forumhome template where ever you want it to display.
i know that, but what code do I have to add to the template?
ericgtr
05-10-2005, 10:34 PM
Can't say without seeing it and having an idea of where you want it.
Adrian Schneider
05-10-2005, 10:47 PM
If you have something like $variable = 1; in your php file, then type $variable to display the 1.
If you have something like $variable = 1; in your php file, then type $variable to display the 1.
i tried that but it didnt work, all the code does is retrieve a number from the database
Adrian Schneider
05-11-2005, 01:04 AM
Maybe something is wrong with your script, because that is how you do it. :)
Could you post the section of code that creates the variable.
$ever = $DB_site->query("SELECT * FROM tablename" );
$totalever = $ever['total'];
$dateever = $ever['date'];
ignore the variable names, they probably wont make any sense to you, im not even sure if this is the correct way to read some thing from the database but I found where it reads something else from the database and copied it and changed a few things
Dean C
05-11-2005, 05:07 PM
$ever = $DB_site->query_first("SELECT * FROM tablename" );
$totalever = $ever['total'];
$dateever = $ever['date'];
Use that :)
filburt1
05-16-2005, 04:25 AM
...but remember to never do SELECT *. Only SELECT what you want to get from the database and nothing more.
Guest190829
05-16-2005, 04:31 AM
Sorry to so called hijack the thread but this may also be useful for jroy.
What's the difference between using just query and query_first?
filburt1
05-16-2005, 04:44 AM
query() returns a handle that you can reference using fetch_row() to fetch sequential rows. query_first() just returns the first row, if any, of the query.
These two are equivalent:
$foo = $DB_site->query_first("SELECT COUNT(*) FROM " . TABLE_PREFIX . "post");
and
$result = $DB_site->query("SELECT COUNT(*) FROM " . TABLE_PREFIX . "post");
$foo = $DB_site->fetch_array($result);
(BTW, SELECT COUNT(*) is fine if there is no WHERE clause, at least in MySQL's case)
Guest190829
05-17-2005, 03:01 AM
Thanks Filburt, now I understand. ^_^
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.