Show Total Image Count on External Website

inebriated

Joined: 2012-07-05
Posts: 11
Posted: Wed, 2014-02-05 22:32

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

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2014-02-05 23:10

I would think that would be the best and only solution.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
inebriated

Joined: 2012-07-05
Posts: 11
Posted: Thu, 2014-02-06 00:52

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)

 
spags

Joined: 2010-03-26
Posts: 120
Posted: Thu, 2014-02-06 08:27

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.

 
tempg

Joined: 2005-12-17
Posts: 1857
Posted: Sat, 2014-02-15 04:13
inebriated wrote:
i dont like the idea of including the user/pass in the file itself

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.

spags wrote:
where type="photo"

Yep.