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
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation please help, unable to display records from a db correctly?

    Hi All,

    i am pulling out the ten soonest ending codes from a db table and i want to group the codes that:

    are ending in less than 1 day
    are ending in 1 day
    are ending in a number of days

    and each of these groups i want the list of codes to show up underneath, but i cant get more than one code to show for each section?

    here is my code
    PHP Code:
        $codes = "SELECT codeID,codeLink,storeID,details,expireDate 
        FROM codes 
        WHERE expireDate >= CURDATE() 
        ORDER BY expireDate ASC LIMIT 0, 10";
        $query = mysql_query($codes)or die(mysql_error);
        $query_rows = mysql_num_rows($resultset);

                    
        while($row=mysql_fetch_assoc($query))
        {
            $storeID = $row['storeID'];    
            $storeLink = htmlspecialchars($row['codeLink']);            
            $date1 = time();
            $date2 = explode("-",$row['expireDate']);
            $expireTime = mktime(0,0,0,$date2[1],$date2[2],$date2[0]);
            $dateDiff = $expireTime - $date1;
            $fullDays = floor($dateDiff/(60*60*24));      
            
                if($lastDate!=$row['expireDate'])
                {
                    #get store name
                    $storeNames = "SELECT storeName FROM stores WHERE storeID = '$storeID'";
                    $sql = mysql_query($storeNames) or die (mysql_error());
                    $name = mysql_fetch_array($sql);
                    $name = htmlspecialchars($name['storeName']);
                    $lastDate=$row['expireDate'];
                    $shortCode_Desc = preg_replace("/.{0}(Valid | Expires | - expires ).*/", "", $row['details']) . "\n";
                    
                    if($fullDays < '1')
                    {?>
                        <div class="code_ending_vsoon_container">
                        <div class="code_ending_header">
                        Hurry!! Less Than 1 Day Left
                        </div>
                           <div class='individual_code_container'>
                           <div class='code red'>
                        <a href='<?php echo $storeLink;?>'>
                        <?php echo $row['codeID'];?> (<?php echo $name;?>)
                        </a>
                        </div>
                           <div class='description small'><?php echo $shortCode_Desc;?></div>
                           </div></div><?php

                    
    }
                    elseif(
    $fullDays == '1')
                    {
    ?>
                        <div class="code_ending_soon_container">
                        <div class="code_ending_header">                
                        Expiring In 1 Day
                        </div>
                           <div class='individual_code_container'>
                           <div class='code red'><a href='<?php echo $storeLink;?>'><?php echo $row['codeID'];?> (<?php echo $name;?>)</a></div>
                           <div class='description small'><?php echo $shortCode_Desc;?>
                           </div></div></div><?php

                    
    }
                    else
                    {
    ?>
                        <div class="code_ending_other_container">
                        <div class="code_ending_header">
                        Expiring In <?php echo $fullDays;?> Days
                        </div>
                           <div class='individual_code_container'>
                           <div class='code red'><a href='<?php echo $storeLink;?>'><?php echo $row['codeID'];?> (<?php echo $name;?>)</a></div>
                           <div class='description small'><?php echo $shortCode_Desc;?>
                           </div></div></div><?php

                    
    }
                }           
        }
    ?>
    any help appreciated
    thanks
    Luke

  • #2
    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
    You have a nice little control break in there, on $_row['expireDate']. But the problem is, you do not have any code to run through if the control doesn't break (in other words, if the current expireDate hasn't changed from the previous expireDate). I assume you want something to happen if the expireDate hasn't changed?

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    hi mate,

    ah i see what you mean, yeah if the code's expire date hasnt changed then i want the next code to print out until all the codes have been printed that match the last expire date.

    but im not sure how to progress with it?

    thanks
    Luke

  • #4
    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
    I wasn't sure why you were even messing with that $lastDate business, but upon further inspection it seems you are using it to determine when to fire off that query on the stores table. But that's the only thing that should fall under that "if" statement, or so it would seem. Try closing up that "if" statement right after the query and continuing on with the $fullDays evaluations after that.


  •  

    Posting Permissions

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