...

View Full Version : please help, unable to display records from a db correctly?



LJackson
02-10-2010, 02:37 PM
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

$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

Fumigator
02-10-2010, 03:58 PM
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?

LJackson
02-10-2010, 04:10 PM
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

Fumigator
02-10-2010, 04:52 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum