By JonGirard-1 on
Hi,
I want to be able to display the number of image nodes that are on the site, in numeric form. (EX: if there are 103 image nodes on the site, then print the number "103.")
I looked into the count function, and found something like this. I placed it where I wanted the number to print on my page..
<?php
$node_types = node_get_types('image');
print("<ul>\n");
foreach ($node_types as $type => $name) {
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'image'", image));
print("<li>$name : $count</li>\n");
}
print("</ul>");
?>
but it doesn't work for me.
Any help is appreciated,
Jon.
Comments
You have some "extra" code
You have some "extra" code in there, not sure if it is causing a problem, here is a simpler version.
Thanks, that works great
Thanks, that works great now.
I've thought about it further though, and I'd like to take it one step further, and output that number onto a dynamically created PNG image. I've gotten to the point where the image generates fine, and I can put text on it, but I can't seem to get the count number to print on it.
This is the code I'm attempting to use in "imagecreate.php" which I've placed in my site folder..
Is this possible to do?
Thanks,
Jon
A multitude of issues,
A multitude of issues,
print("$count")should be simply$count, you need to set $count before you use it. The big problem though is without some extra code it will simply not work since db_result, db_query and the connection to the database has not been made. Search for "bootstrap" for solutions to this.Another approach is to call the script as imagecreate.php?count=3 (or some number) then at the start of the script do
$count = $_GET['count']. The code that creates the link would then do the db work.I searched bootstrap, and
I searched bootstrap, and looked as if it would be something which would really require me to dive in deep, no?
Thus, I gave the second approach a try, and it seems to work pretty well.. Still though, I'm completely stumped with a few things:
1) In my style.css for a menu item, I'm calling the dynamic image: "#block-menu-184 ul.menu li.leaf {
background-image:url(/sites/all/themes/BDC/imagecreate.php?count=);"
Of course, the problem is since style.css is a seperate file, I'm not sure how I'd get the dynamic number to print beside the "=" in the url (currently as you can see I just have it as "?count=")
It's looking as if I'll have to go with the original bootstrap way most likely I'm guessing..?
Jon.