Click to See Complete Forum and Search --> : New Submissions


NaOH
December 20th, 2007, 10:09 PM
Hi there,

I've got a photography portfolio, and I've written some code to query an SQL database for any photos submitted within the last week. The code is as follows:

<?php
$host="localhost";
$username="******";
$password="******";
$database="******";
$siteurl="http://www.oxidephoto.ca";
//Database Connection
$connection = mysql_connect($host, $username, $password);
$db = mysql_select_db($database);

$q = "SELECT * FROM `plogger_pictures` WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= date_submitted";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))
{
$collection=$row["parent_collection"];

}

?>

This code exists within a while-db-has-pictures loop.

Also within this loop is the code to generate a 'NEW!' next to a new picture:

<?php if ($collection == plogger_get_collection_id()) {echo "NEW! ";} ?>

This works, technically, but the problem that I'm having is it does it to the most recent photo only, and if there's any others that apply (if I submit three in a day or something), they aren't highlighted.

Anyone have any idea why that might be?

Thanks for your help!

PeejAvery
December 20th, 2007, 11:21 PM
...but the problem that I'm having is it does it to the most recent photo only, and if there's any others that apply (if I submit three in a day or something), they aren't highlighted...
It would seem that $collection is a unique ID. If this is the case, then it will only ever return 1.

NaOH
December 21st, 2007, 02:02 AM
So what's the fix for that?

PeejAvery
December 21st, 2007, 07:46 AM
Your best way would be to have a timestamp column in your database. Then you can find the newest timestamp and set all with that to echo new.

EDIT: Your format for timestamp must be YYYYMMDD (Ymd in PHP). That way it will match the day and not hours, minutes, or seconds.

NaOH
December 22nd, 2007, 08:50 PM
That won't work, though, because I'm using a CMS to organize the photos, and I'm not good enough with PHP or anything to get that done. How else could this be accomplished? Could I use an array or something?

PeejAvery
December 23rd, 2007, 05:56 PM
Yes, you could use an array and put the new images in that.

$new = array(
'image1.jpg',
'image2.jpg',
'image3.jpg'
);

foreach($new as $image){
if($image == $row['imagename']){echo 'New';}
}