SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script stopping unexpectantly

    The following script stops processing for some reason at the marker indicated. Well the echos are ignored anyway, the mysql seems to run fine. If the mysql related stuff after the indicated point is commented out it runs fine, but seeing as the two echo statements are outside of the while loop, they should echo regardless. Its not the 'or die' of the mysql stopping as no error is output, and if you only comment out the while loop (and leaving in the mysql or die), the echos are successful.

    Driving me crazy! Anyone help?

    Dan

    PHP Code:
    <?php
    include('dbconnect.php');
    //$uid = $_SESSION['uid'];
    $uid 'dmorgan';
    $privatenew "SELECT * FROM messages WHERE uidto='$uid' AND viewed=0 ORDER BY id DESC";
    $privatenewresults mysql_query($privatenew);
    $privatenewnum mysql_num_rows($privatenewresults) or die(mysql_error());
    $i 0;
    echo 
    "<table>\n<tr colspan=\"3\">\n<td>Unread Messages:</td>\n</tr>\n<tr>\n<td>Subject</td>\n<td>Sender</td>\n<td>Date</td>\n</tr>\n";
    while (
    $privatenewnum $i) {
        
    $title mysql_result($privatenewresults$i"title");
        
    $from mysql_result($privatenewresults$i"uidfrom");
        echo 
    "<tr>\n<td>$title</td>\n<td>$from</td>\n<td>Timestamp</td>\n</tr>\n";
        
    $i++;
    }
    echo 
    "</table>";
     
    // Nothing echos below this point.  
    // Query wont return any data but it should still echo table structure.
     
    $privateold "SELECT * FROM messages WHERE uidto='$uid' AND viewed=1 ORDER BY id DESC";
    $privateoldresults mysql_query($privateold);
    $privateoldnum mysql_num_rows($privateoldresults) or die(mysql_error());
    $i 0;
    echo 
    "<table>\n<tr colspan=\"3\">\n<td>Read Messages:</td>\n</tr>\n<tr>\n<td>Subject</td>\n<td>Sender</td>\n<td>Date</td>\n</tr>\n";
    while (
    $privateoldnum $i) {
        
    $title mysql_result($privateoldresults$i"title");
        
    $from mysql_result($privateoldresults$i"uidfrom");
        echo 
    "<tr>\n<td>$title</td>\n<td>$from</td>\n<td>Timestamp</td>\n</tr>\n";
        
    $i++;
    }
    echo 
    "</table>";
    ?>

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the first WHILE loop works - for new messages and not the second WHILE loop then it's the database query that's wrong.

    I've never been a fan of mysql_result(...) myself, thus I generate a 2 dimension array instead:

    [field][rec]..
    [field][rec].. etc for every record found thus I do not use said mySQL function 8)

    How it can be the database query defies me though since both pieces of script are basically the same 8(

  3. #3
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    include('dbconnect.php');
    //$uid = $_SESSION['uid'];
    $uid 'dmorgan';
    $privatenew "SELECT * FROM messages WHERE uidto='$uid' AND viewed=0 ORDER BY id DESC";
    $privatenewresults mysql_query($privatenew);
    $privatenewnum mysql_num_rows($privatenewresults) or die(mysql_error());
    $i 0;
    echo 
    "<table>\n<tr colspan=\"3\">\n<td>Unread Messages:</td>\n</tr>\n<tr>\n<td>Subject</td>\n<td>Sender</td>\n<td>Date</td>\n</tr>\n";
    while (
    $privatenewnum $i) {
        
    $title mysql_result($privatenewresults$i"title");
        
    $from mysql_result($privatenewresults$i"uidfrom");
        echo 
    "<tr>\n<td>$title</td>\n<td>$from</td>\n<td>Timestamp</td>\n</tr>\n";
        
    $i++;
    }
    echo 
    "</table>";
     
    // Nothing echos below this point.  
    // Query wont return any data but it should still echo table structure.
     
    $privateold "SELECT * FROM messages WHERE uidto='$uid' AND viewed=1 ORDER BY id DESC";
    $privateoldresults mysql_query($privateold);
    $privateoldnum mysql_num_rows($privateoldresults) or die(mysql_error());
    echo 
    "<table>\n<tr colspan=\"3\">\n<td>Read Messages:</td>\n</tr>\n<tr>\n<td>Subject</td>\n<td>Sender</td>\n<td>Date</td>\n</tr>\n";
    for (
    $i 0$i <$privateoldnum$i++)
        
    $title mysql_result($privateoldresults$i"title");
        
    $from mysql_result($privateoldresults$i"uidfrom");
        echo 
    "<tr>\n<td>$title</td>\n<td>$from</td>\n<td>Timestamp</td>\n</tr>\n";

    echo 
    "</table>";
    }
    ?>
    Please note, I take no responsibility for the changes I just made in the code.. I didn't even read over most of the code at all, so I couldn't even begin to tell whether or not this will work nor whether or not it's what you're looking for.
    Last edited by CeleronXL; Apr 20, 2003 at 10:17.

  4. #4
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    If the first WHILE loop works - for new messages and not the second WHILE loop then it's the database query that's wrong.

    I've never been a fan of mysql_result(...) myself, thus I generate a 2 dimension array instead:

    [field][rec]..
    [field][rec].. etc for every record found thus I do not use said mySQL function 8)

    How it can be the database query defies me though since both pieces of script are basically the same 8(
    Well exactly, but seeing as the echos are inline and are not affected by anything else, no if, while, for ect logic, the mysql should be academic. No matter what the mysql does it should echo those lines, i.e. the ones outside the while loop.

    With regard to the mysql functions, I am still very much learning stuff [img]images/smilies/smile.gif[/img]

    Celeron, thanks, Ill take a look at what you posted.

    Dan

  5. #5
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by glenplake
    Well exactly, but seeing as the echos are inline and are not affected by anything else, no if, while, for ect logic, the mysql should be academic. No matter what the mysql does it should echo those lines, i.e. the ones outside the while loop.

    With regard to the mysql functions, I am still very much learning stuff [img]images/smilies/smile.gif[/img]

    Celeron, thanks, Ill take a look at what you posted.

    Dan
    Took a quick look at it and made a slight change..

  6. #6
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I had to add a { after the for condition and move one too (didnt want </table> after each row), but that looks peachy.

    Appreciated.

    Dan (still confused about what I had to start with though )


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
  •