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 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    85
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Exclamation Nesting ifs with specific values taken from mysql

    Good morning everyone,

    I've been trying to nest a few if statements for a newsletter that first checks for users in the database that are part of a particular group (ex: Retail, Distributors, TEST), and then I have another if statement that checks if they want to receive the newsletter (simple "YES" or "NO" in that field).

    Here's my code for the group "TEST":
    PHP Code:
                                                        elseif($ngroup == "TEST")
                                                        {
                                                            
    mysql_select_db($database_TireSafe_Database$TireSafe_Database);
                                                            
    $ngroupselection "SELECT * FROM TS_NEWSLETTER WHERE `group` = 'TEST'";
                                                            
    $Newsletter mysql_query($ngroupselection$TireSafe_Database) or die(mysql_error());
                                                            
    $row_Newsletter mysql_fetch_assoc($Newsletter);
                                                            
    $totalRows_Newsletter mysql_num_rows($Newsletter);
                                                                do {
                                                                                if(
    $nreceive == "YES")
                                                                                {
                                                                                    
    mysql_select_db($database_TireSafe_Database$TireSafe_Database);
                                                                                    
    $nreceiveselection "SELECT * FROM TS_NEWSLETTER WHERE `receive` = 'YES'";
                                                                                    
    $Newsletter mysql_query($nreceiveselection$TireSafe_Database) or die(mysql_error());
                                                                                    
    $row_Newsletter mysql_fetch_assoc($Newsletter);
                                                                                    
    $totalRows_Newsletter mysql_num_rows($Newsletter);
                                                                                    
                                                                                    
    $ngroupemails $row_Newsletter['email'] . ", ";
                                                                                    }
                                                                            }
                                                                            while (
    $row_Newsletter mysql_fetch_assoc($Newsletter));

    How can I fix this? I know there's a lot of unnecessary coding in there, I can tell, but can someone point it out for me? The coding for the other groups looks the same as this, so if I know how to fix TEST, then I'll be able to figure out how to structure the rest correctly.

    I'd greatly appreciate it!

    Thank you all very much in advance

  • #2
    New Coder
    Join Date
    Jan 2008
    Posts
    85
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey guys, nevermind.

    I fixed it after looking at some logical solutions. It was staring at me in the face. I had to insert the do...while statement inside the second if statement.

    Here's what I did to fix it if anyone who read my post wants to know:

    PHP Code:
    elseif($ngroup == "TEST")
    {
        
    mysql_select_db($database_TireSafe_Database$TireSafe_Database);
        
    $ngroupselection "SELECT * FROM TS_NEWSLETTER WHERE `group` = 'TEST'";
        
    $Newsletter mysql_query($ngroupselection$TireSafe_Database) or die(mysql_error());
        
    $row_Newsletter mysql_fetch_assoc($Newsletter);
        
    $totalRows_Newsletter mysql_num_rows($Newsletter);
            if(
    $nreceive == "YES")
                {
                                
    mysql_select_db($database_TireSafe_Database$TireSafe_Database);
                                
    $nreceiveselection "SELECT * FROM TS_NEWSLETTER WHERE `receive` = 'YES'";
                                
    $Newsletter mysql_query($nreceiveselection$TireSafe_Database) or die(mysql_error());
                                
    $row_Newsletter mysql_fetch_assoc($Newsletter);
                                
    $totalRows_Newsletter mysql_num_rows($Newsletter);
                    do {
                                
    $ngroupemails $row_Newsletter['email'] . ", ";
                        }
                        
                        while (
    $row_Newsletter mysql_fetch_assoc($Newsletter)); 
                }

    Thanks.


  •  

    Posting Permissions

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