Forum Moderators: coopster
mysql
-----
title VARCHAR(40),
details VARCHAR(9999),
oldprice VARCHAR(30),
newprice VARCHAR(30),
expires VARCHAR(30), //unix time stamp
expiretext VARCHAR(30), // formatted output of 'expires'
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id))")
php
---
// grab info from db
$query = "SELECT * FROM featuredsales ORDER BY RAND() LIMIT 0,1 ";
$result = mysql_query($query);
// start html for looped data
echo '<div class="sales_display">';
// begin loop from db
while($row = mysql_fetch_array($result))
{
// compare dates for expired items
if(strtotime($row['expiretext']) > strtotime($today)){
// get price difference for amount saved
$savings = $row['oldprice'] - $row['newprice'];
$savings_percentage = round( ($savings/$row['oldprice'])*100, 0 );
// make date more readable
$sale_expiry = date('F jS, Y', strtotime($row['expiretext']));
// display active items
echo '<div id="sale_'.$row['id'].'">
<h3>'.$row['title'].'</h3>
<p><strong>Now: $'.$row['newprice'].'</strong><br />
Was: $'.$row['oldprice'].'<br />
You Save: $'.$savings.' ('.$savings_percentage.'%)</p>
<div class="mce_output" id="sale_'.$row['id'].'_details">'.$row['details'].'</div>
<p>(<em>this sale expires on '.$sale_expiry.'</em>)</p>
</div>
<hr />';
// don't display expired items
} else {
echo ''; }
// end sales loop
}
// end html for looped data
echo '</div>';
mysql_close($conn);
[edited by: eelixduppy at 8:36 pm (utc) on Feb. 28, 2009]
[edit reason] disabled smileys [/edit]
$today = time();
$query = "SELECT * FROM featuredsales WHERE expires > $today ORDER BY RAND() LIMIT 0,1 ";
'$today' returns the current timestamp, but I can't seem to get it working in the select. Either nothing displays or I get the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in . . .
Am I using the wrong syntax in the query?