Thread: adding problem

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    65
    Rep Power
    15
    My script first takes the number of messages on a board that were posted in the last seven days, and then gets the replies to those messages. The script then adds them up to produce two variables, $num and $num2. It doesn't add in the replies for the last message in the count though.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$hola1 = mysql_query("select * from messages where (isreplyto = '0') AND (DAYOFYEAR(now()) - DAYOFYEAR(date) <= '7') ORDER BY id DESC");
    if ($polly = mysql_fetch_array($hola1)) {
    $num = mysql_num_rows($hola1);
    if (1 == '1') {
    $num2 = '0';
    if ($doofus = mysql_fetch_array($hola1)) {
    do {
    $killer = $doofus["id"];
    $dip = mysql_query("select * from messages where isreplyto = '$killer'");
    $getem = mysql_num_rows($dip);
    $num2 = $num2 + $getem;
    } while($doofus = mysql_fetch_array($hola1));
    }
    [/code]
    Is there an obvious problem that I am missing, or am I just nuts?
    TIA,
    Ben


    [This message has been edited by FerretComp (edited October 18, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Newark, DE, USA
    Posts
    39
    Rep Power
    14
    I can't begin to say what's wrong with your code. I had to change things around a lot before I could begin to understand what you were trying to do. I ended up with this, though ....
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $getMessages = mysql_query("select id from messages where (isreplyto = '0') AND (DAYOFYEAR(now()) - DAYOFYEAR(date) <= '7') ORDER BY id DESC");
    $numMessages = mysql_num_rows( $getMessages );
    $totalReplies = 0;
    while( list( $messageID ) = mysql_fetch_row( $getMessages ) ){
    $getReplies = mysql_query( "select id from messages where isreplyto='$messageID'" );
    $numReplies = mysql_num_rows( $getReplies );
    $totalReplies += $numReplies;
    }

    $grandTotal = $numMessages + $totalReplies;
    [/code]

    ------------------
    ~Chris

    [This message has been edited by cwwesley (edited October 18, 2000).]

    [This message has been edited by cwwesley (edited October 18, 2000).]

Similar Threads

  1. UTF-8 problem in 4.1.1a
    By mehran20 in forum MySQL Help
    Replies: 1
    Last Post: February 8th, 2004, 02:21 PM
  2. Wierd problem inserting data with VB6
    By gregquinn in forum MySQL Help
    Replies: 5
    Last Post: February 2nd, 2004, 07:37 AM
  3. Adding onto a network problem
    By chales in forum Networking Help
    Replies: 1
    Last Post: January 31st, 2004, 02:10 PM
  4. WinNT4 problem
    By sandipguha in forum Windows Help
    Replies: 0
    Last Post: January 27th, 2004, 02:06 AM
  5. weird java problem..please help
    By suwandy in forum Java Help
    Replies: 1
    Last Post: January 26th, 2004, 04:13 AM

IMN logo majestic logo threadwatch logo seochat tools logo