|
Posted by Daedalus.OS on 06/03/05 13:28
I would get the number of pictures in the db, then make a modulo based
operation on the timestamp:
// query from db to get $image_tot
$img_day_num = 2; // This tell how many image we want to have per day
$image_tot = mysql_query($query); // Let's say we got 800
$day_epoch = round(time()/(60*60*24)); // Let's say we got 12941 (wich is
june 3 2005)
/*
Now since we want 2 image per day, we will make a modulo on $day_epoch
divided by 2 to have a number for each day that will be between 0 and 399
then by multiplying the result by two we will find the lowest image number
(since MySQL index start at 0), 0*2 = 0(img0 & img1), 1*2=2(img2 & img3),
2*2=4(img4 & img5) and so on...
*/
$low_image = $day_epoch%($image_tot/$img_day_num)*$img_day_num; // return
274 in this exemple
$high_image = $low_image+1; // return 275 in this exemple
now to retrive the image in MySQL, simple specify $low and high image as
LIMIT
$query_img = "SELECT filename, alt FROM some_table LIMIT $low_image,
$high_image";
// In our exemple since $low_ and $high_ image are 274 and 275, this will
retrive row 275 and 276 (index start at 0 but row start at 1, LIMIT use
indexes)
I don't know if it's elegant but it's reliable and absolutely dynamic.
Dae
>...
> I expect that I would put together a kludge of every picture having an
> auto-increment id number, on day 1 showing 2 successive pictures with id
> number N and N+1, filing a value for the next N each time.
> There will be people in this group who will provide a far more elegant
> solution than the above, but as you will be increasing the number of
> pictures, the whole thing needs to be dynamic, and also cater for your
> deleting any pictures, already shown or yet to be shown.
> I'll be interested to see the others' suggestions.
>
> (By the way, Luigi - don't worry too much; I can't speak *your* native
> language with ANY degree of fluency.)
Navigation:
[Reply to this message]
|