SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 54
  1. #26
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    do you have phpmyadmin or anything similar?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  2. #27
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I've made a script to submit mysql queries

  3. #28
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then what error message are you getting with phpdaemon's code?

    And the last query you posted is still what you posted before! The query I posted earlier works; I tested it.

    spikeZ, apparently SUM, much to my amazement and much towards making me look a full for all my advocation of it above, only accepts one column. I tested it and got an error trying to stuff in multiple columns.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  4. #29
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not getting a error message with any code.. It's just a blank screen like it's not even connecting... but I have the same connection thing right above it and that code works.

  5. #30
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be getting an error. Did you add the error_display setting and error_reporting turned to E_ALL? There must be an error, or else it would not be a blank page.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  6. #31
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I added that in at the code at the top.

  7. #32
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    How about posting your full code? I've a feeling you're hiding something from us.
    Saul

  8. #33
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well my whole code is 9,000 lines long..

  9. #34
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put an echo statement in to echo $query back. Is the Query valid? Is table the name of the table?

  10. #35
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when I put the select statement through the query it works, and now I've got it to actually show up but it gave me like 400 errors.

  11. #36
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the latest code, i know the select statement works.

    <?php
    mysql_select_db(time_com, $connection);

    $sql = "SELECT sum(monreghours0 + monreghours1 + monreghours2 + monreghours3 + monreghours4) AS total FROM timesheet WHERE username='$_SESSION
    [user_name]'";
    $result = mysql_query($sql);
    #or die(mysql_error());

    $total = 0;
    while ($row = mysql_fetch_array($result)) {
    $total = $row['total'];
    }

    echo $total;
    ?>

  12. #37
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rename your table to something like hours, table is a reserved name.

  13. #38
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my table isn't named table its timesheet

  14. #39
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is your first error?

  15. #40
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem lies here:

    while ($row = mysql_fetch_array($result))
    {
    $total = $row['total'];
    }

    i've tested everything else, and it shows total = 0 when that is commented out.

  16. #41
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what it should be though.

  17. #42
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Echo back $row['total']. What do you get?

    Try : while ( $row = mysql_fetch_assoc( $result )) { $total = $row['total']; }

  18. #43
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    showed nothing

  19. #44
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait, shouldn't you be using +=, if you want to add up everything? I thought that's what you had earlier.

    And you said in your other post you had 400 errors.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  20. #45
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The errors weren't in regards to this piece of code, and I do have the += in there, it says it's equal to 0, but have added them and didn't

  21. #46
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Retrieve the data and add the fields in each row inside the while loop. Echo each field back to see what your data looks like.

  22. #47
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not really sure what you mean there

  23. #48
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your query looks fine. The only problem I really see is your time_com not being in quotes. (If it is a string, it should be in quotes..) You won't need to do a while loop if you're only returning 1 row result. If you have multiple rows that you intend to return, then you will need to have the while loop.

    PHP Code:
    <?php 
    mysql_select_db
    ("time_com"$connection); /*If this line is already specified above in your code, you shouldn't need it. */
     
    $sql "SELECT sum(`monreghours0` + `monreghours1` + `monreghours2` + `monreghours3` + `monreghours4`) AS `total` FROM `timesheet` WHERE `username`='".mysql_real_escape_string($_SESSION['user_name'])."'";
    $result mysql_query($sql) or die(mysql_error()); 
     
    $total 0
    $row mysql_fetch_array($result);
    $total $row['total']; 
     
    /* if you're planning on returning more than 1 result 
     
    while ($row = mysql_fetch_array($result)) 

        $total += $row['total']; 
    }
     
    */
    echo $total
    ?>
    However, with all that being said, you should check that the username session is actually correct.

    PHP Code:
    // At the top of your page.
    print_r($_SESSION);
    // or
    echo 'Session Username: ' $_SESSION['user_name']; 
    When debugging, echo everything. Echo out your variables and see if you are getting what you expect to get. It really helps to understand what your script is doing, so you can fix it, to do what it is supposed to.

    Another way to turn on error reporting is to create a .htaccess file in the same directory of your script and put this in it:

    PHP Code:
        php_flag display_errors on
        php_value error_reporting 7 

  24. #49
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by devbanana View Post

    spikeZ, apparently SUM, much to my amazement and much towards making me look a full for all my advocation of it above, only accepts one column. I tested it and got an error trying to stuff in multiple columns.
    Are you sure? I tested it on a simple table with 3 columns and it worked fine....

    Might be time to hoof this thread over to the mysql forum....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  25. #50
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow thanks Tmapm, It works!!!!


Bookmarks

Posting Permissions

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