Hi there, I have my gallery installed on a subdomain of an already popular site, for example gallery.mysite.com
What I would like to acheive is to display the total number of images in the gallery on my main domain mysite.com
Im fairly competent in PHP and MySQL and was thinking of just connecting to the gallery DB from the main site and counting the image count somehow (havent looked at db structure yet) and then echo'ing it out.
Is this the best way to go about this or is there an alternative solution?
Kind Regards
Andy
Posts: 27300
I would think that would be the best and only solution.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 11
Done and works a charm,
Here is what I did :
<?php
$con = mysql_connect("localhost","MYDBUSER","MYPASS");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MYDATABASE", $con);
$result = mysql_query("select count(1) -1 FROM items");
$row = mysql_fetch_array($result);
$total = $row[0];
echo "Total Images: " . $total;
mysql_close($con);
?>
Works fine for me, although I read that I should use mySQLi instead of just mySQL
Or even better, could I include the gallerys installation to establish the database connection? if so which files do I need to include? (i dont like the idea of including the user/pass in the file itself)
Posts: 120
You need to amend your SQL statement because you are also including the count of the number of albums in the gallery as well.
Sorry I don't remember exact column names and values (you might need to hunt around the database a bit to check), but it would be something like this:
select count(1)-1 from items where type="photo"
There are also "movie" item types as well. Maybe you are better off selecting where the type isn't "album", but that all depends on what you really want.
Posts: 1857
Ditto that.
I'm not sure of a way to tap directly into Gallery to pull that info.
I'd maybe run a cron to have Gallery write the total to a file every day (or however often) and read it in from there.
You could also have the count write trigger from some other action (e.g. uploading/deleting images) and integrate it into Gallery's main code, but that may require editing the core.
Yep.