Display no. of images hosted?

Discussion in 'PHP' started by Rakaan, Jun 25, 2007.

  1. #1
    Hiya,

    How can I display number of images hosted on my imagehosting service somewhere on the front page?

    http://www.imagegrip.com

    Thanks in advance.

    Cheers :)
     
    Rakaan, Jun 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Are you tracking the uploads in a database? Or are the images just stored in a folder? Or folders? Provide more information...
     
    nico_swd, Jun 25, 2007 IP
  3. Rakaan

    Rakaan Well-Known Member

    Messages:
    256
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Images are stored in a folder and tracking in enabled in the database as well. I am not an expert, it just in phpmyadmin, I see the same number of images which are uploaded in the upload folder.

    Is it of any help at all?
     
    Rakaan, Jun 26, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    
    $query = mysql_query("SELECT COUNT(*) AS total FROM your-table");
    $images = mysql_fetch_assoc($query);
    
    echo $images['total'];
    
    PHP:
    This should work. Make sure a MySQL connection is established when calling this script. And you'll have to replace "your-table" with the actual table name where the images are tracked.
     
    nico_swd, Jun 26, 2007 IP
  5. Rakaan

    Rakaan Well-Known Member

    Messages:
    256
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Thanks a lot nico_swd. This works :D

    Cheers
     
    Rakaan, Jun 26, 2007 IP
  6. KlearConcepts

    KlearConcepts Peon

    Messages:
    349
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That way would work but you could also count how many files in the directory and minus 1 for the htaccess etc. This should work the same and give the same number so you could compare these two numbers./
     
    KlearConcepts, Jun 26, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    it would actually be - 3 for the .htaccess and . and .. but that is the wrong way to go about it. nico's method is spot on. there's no point in looping through the files in the directory and checking meta data to be sure that is in fact an image when all you have to do is a single sql query to get the total number of images.
     
    ansi, Jun 26, 2007 IP