+ Reply to Thread
Results 1 to 8 of 8

Thread: Little PHP help

  1. #1
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Little PHP help

    I have this query

    PHP Code:
    <?php
    $album_views 
    mysql_query("SELECT SUM(views) FROM `photo_albums`") or die(mysql_error());
    ?>
    There have been <?php echo $album_views?> total album views.
    and i am getting resource ID #21

    basically i want the number of views for the photo albums but when i run that i get the error

    but when i put that into phpmyadmin it works. anybody know whats wrong

    I would love to change the world, but they won't give me the source code

  2. #2
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: Little PHP help

    Try this

    PHP Code:
    $album_views mysql_query("SELECT SUM(`views`) FROM `photo_albums`") or die(mysql_error()); 
    Ill look more into it tommarrow
    </span></span>
    Thanks,
    Brandon Long

  3. #3
    Corey's Avatar
    Corey is offline VPS Migration Professional Corey is a glorious beacon of lightCorey is a glorious beacon of light
    Join Date
    Dec 2004
    Location
    Northfield, NH
    Posts
    17,151

    Re: Little PHP help

    Do print_r($album_views) and see what is says, usually a resource ID means it's in an array.

    -Corey

  4. #4
    acidburn0520's Avatar
    acidburn0520 is offline x10 Sophmore acidburn0520 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Florida, USA
    Posts
    117

    Re: Little PHP help

    Shouldn't you be using $album_views['views'] rather than just $album_views?

  5. #5
    Torch's Avatar
    Torch is offline x10 Lieutenant Torch is an unknown quantity at this point
    Join Date
    Apr 2006
    Location
    Belgrade, Serbia
    Posts
    317

    Re: Little PHP help

    Actually, mysql_query with SELECT statement returns a resource which isn't very useful to you untill you pass it to some function that converts it to data. In your case, the best one would be mysql_fetch_array. So what you need to do is:
    PHP Code:
    <?
    $album_views 
    mysql_query("SELECT SUM(views) FROM `photo_albums`") or die(mysql_error());
    $album_views mysql_fetch_array($album_views); //Makes an array out of internal object/resource
    ?> 
    There have been <?=$album_views[0]?> total album views.
    There you go, it should work
    Last edited by Torch; 12-06-2006 at 01:36 PM.

  6. #6
    acidburn0520's Avatar
    acidburn0520 is offline x10 Sophmore acidburn0520 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Florida, USA
    Posts
    117

    Re: Little PHP help

    Oh yeah... I'm so used to vBulletin -- it uses OOP, so everything is $db.

  7. #7
    Origin's Avatar
    Origin is offline x10 Elder Origin is an unknown quantity at this point
    Join Date
    Mar 2005
    Location
    Silicon Valley, California
    Posts
    541

    Re: Little PHP help

    Plus you need to set it as SUM(views) as sum_of_views instead.


    Visit OriginXT.COM Network! It has a popular RPG, featuring a battle system, an original RPG Shop, and much more! In addition to the RPG, we also feature a community with almost a quarter million posts, hundreds of free games in the arcade, free downloads and even an instant chatroom! Just come on and join the 1500 community members in hot debates and fun; you're SURE to love it!

    My blog (Origin XT Blog), Homepage and WebClubs.org

  8. #8
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Little PHP help

    torches worked. sorry it took me so long to answer

    I would love to change the world, but they won't give me the source code

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  4. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers