...

View Full Version : Highlighting latest added records ?



maikelv
02-21-2008, 09:01 PM
Hi there,

I am building a simple "movie database" script for personal use in php. It's just some practise to get a bit better at it.

Now, My movies are alphabeticly listed, but I would like to highlight the last 3 added films.
I guess this should be possible ? I have id & title for each film in my mysql table.

Thanks alot for reading :)

_Aerospace_Eng_
02-21-2008, 10:10 PM
You could probably add another column that holds the unix timestamp for when the movie was added then use a query like this

$query = "SELECT * FROM tablename ORDER BY timeadded DESC LIMIT 3";
That should give you the lastest 3 entries. You can probably do something like this as well

$query = "SELECT * FROM tablename ORDER BY id DESC LIMIT 3";

o0O0o.o0O0o
02-22-2008, 12:54 AM
Your all movies are in one section or are there any different categories

Probably there will be different categories of movies and do you want to show last three in every section or as a whole

Ultragames
02-23-2008, 12:40 AM
If you have a time added feild, then you can do something like this:


SELECT * FROM movies ORDER BY movie_name ASC

And run this as well, to get the IDs for the latest 3.


SELECT movie_id FROM movies ORDER BY time_added DESC LIMIT 3

Then when you loop through the movies, just check to see if the movie you are displaying is within the results of the last query above.

maikelv
03-01-2008, 09:17 AM
Then when you loop through the movies, just check to see if the movie you are displaying is within the results of the last query above.

The previous steps work perfectly, only I don't know how to do the check. Can anyone enlighten me on this? :)

Thanks !

Ultragames
03-01-2008, 09:22 AM
it depends on how you are looping through the first query. The easiest way to do it is to create an array out of the second query, and then run an in_array() on the loop for the first query.

maikelv
03-01-2008, 09:40 AM
it depends on how you are looping through the first query. The easiest way to do it is to create an array out of the second query, and then run an in_array() on the loop for the first query.


<?php
case view:
if ($_POST['genre']=="alles") {
$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id";

}
else {
$query = "SELECT *
FROM divx INNER JOIN genres ON genreid=genres.id
WHERE genreid = \"{$_POST['genre']}\"";
} ?>
<table class="result">
<tr>
<td class="top">Titel</td>
<td class="top">Genre</td>
</tr>
<?php
if ($result=$link->query($query)) {
for ($i=0; $i < $result->num_rows; $i++) {
$rij= $result->fetch_assoc();
print("<tr>\n");
print("<td class=\"cell1\"><a href=\"http://www.imdb.com/find?s=tt&q={$rij['titel']}\" class=\"titel\">{$rij['titel']}</a></td>\n");
print("<td class=\"cell2\">{$rij['genre']}</td>\n");
print("</tr>\n");

}
$result->close();
}
$link->close() or die("Kan link met $dbserver niet sluiten.");
?>
</table>
<a href="film.php">Terug</a>
<?php
break;

This is the code I m using right now. The if check is for sorting by genre. Than I put the results in the $rij array.

maikelv
03-06-2008, 05:53 PM
Bump :)

Inigoesdr
03-06-2008, 06:22 PM
The previous steps work perfectly, only I don't know how to do the check. Can anyone enlighten me on this? :)

Thanks !
You don't know how to do which check?
Have you added a time field?

Andrew Johnson
03-06-2008, 07:08 PM
If your 'id' field is autoincrement then just use the following query:


SELECT * FROM table ORDER BY id DESC LIMIT 3

maikelv
03-07-2008, 08:27 AM
You don't know how to do which check?
Have you added a time field?

The check to see if my results are in t the query for the first 3 results.
(in order to highlight them).

maikelv
03-10-2008, 09:05 AM
Anyone ? :)

_Aerospace_Eng_
03-10-2008, 01:45 PM
You haven't answered our questions yet. Have you even tried what we've given you?

Have you added a time field?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum