Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem counting from table

    I'm stumped. I finally got rid of all the MySQL error messages, but the "if" part doesn't seem to work. I want to count the number of Active='0' photos a user has, and if more than ten, then exit the upload process with a message. My problem seems to be with " COUNT(UserID) AS QueueCount" and "if ($QueueCount > 10)". Any suggestions? Here's what I have:

    if ($UserLevel == '4')
    {
    $query = "SELECT PhotoID, COUNT(UserID) AS QueueCount FROM Photos WHERE (Active = '0') AND (UserID = '$SessionUserID') GROUP BY UserID";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
    if ($QueueCount > 10)
    {
    print "You have reached your upload limit.";
    print "When your submissions have been processsed,";
    print "you will be able to resume uploading";
    require ("Footer.php");
    exit;
    }
    }
    }

    Thanks,
    Stan

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    try

    if($row['QueueCount'] > 10)

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    BTW there's no need to select count() from the table-- you can use the mysql_num_rows() function to get the number of rows in any query result. And it is pointless to use GROUP BY on a column that you are filtering down to a single value-- the purpose of GROUP BY is to group rows of the same value together, so when you do WHERE userID = 999 GROUP BY userID it will only return one group (pointless).
    PHP Code:
    $query "SELECT PhotoID FROM Photos WHERE (Active = '0') AND (UserID = '$SessionUserID')";
    $result mysql_query($query) or die(mysql_error());

    if (
    mysql_num_rows($result) > 10) {
        print 
    "You have reached your upload limit.";
        print 
    "When your submissions have been processsed,";
        print 
    "you will be able to resume uploading";
        require (
    "Footer.php");
        exit;
    }

    while(
    $row mysql_fetch_array($result))
    {
    .
    .
    .


  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks whizard and Fumigator. I went with Fumigator's code. I'm still trying to get a grip on this stuff, and if I get something to work, it's usually by guessing as in this case. The redundant code was leftovers from previous attempts.

    I moved things around a bit, I put the "while" under the "$result", and the "if" under the "while". Don't know if that was a good thing or not, but it still works.

    Thanks again,
    Stan


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •