PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Sun Feb 16, 2003 4:49 pm
HI! I am working on a links directory script and need some help. Thanks!
1. How do i get it to show
NEW links? Do I need to add
time() when I am adding the links? What exactly do I need to do? Thanks
2. How do I show how many tables are in a db table?
Thanks for any help you can give!
Tech
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 7:38 pm
1) define new
2) "SELECT count(*) tablename" optional "SELECT count(*) tablename WHERE
condition "
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Sun Feb 16, 2003 8:55 pm
volka wrote: 1) define new
So what code do I add? I'm new to that... Thanks
volka wrote: 2) "SELECT count(*) tablename" optional "SELECT count(*) tablename WHERE condition "
Thanks!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 9:21 pm
I just wanted to know what you mean with new .
1 day old, 3, not seen by the user before, marked as new , ...
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Sun Feb 16, 2003 9:27 pm
Oh, sorry(I thought that was code)
What I meant by
NEW is when someone adds a link, it puts a new image next to the link for a certain amount of days that I choose.
Understand now?
You can find a demo of what i want at:
http://www.webwondersnews.com/resources/
Thanks
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Feb 16, 2003 11:47 pm
if you're using the filesystem to store the data you might use
stat() to retrieve the last modification time of the files contained in a directory.
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Feb 17, 2003 1:30 am
I amy using mySQL.
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Feb 17, 2003 4:28 am
twigletmac answered everyones questions except mine! Thanks for any help
!
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Feb 17, 2003 4:52 am
Mr. Tech wrote: twigletmac answered everyones questions except mine!
Not intentionally...
Do you have a field in your database table that stores the date when the link was added?
Mac
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Feb 17, 2003 6:47 pm
When I add the links to the DB I insert these two:
now()
time()
Are they what I need? Thanks for replying
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Feb 18, 2003 2:20 am
You need to have some sort of test that takes the timestamp from the database, compares it to the current timestamp and if the difference is within a particular timeframe, display the 'new' image and if not don't.
Mac
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Feb 18, 2003 3:07 am
I tend to let mysql perform the comparison of values stored in it, esp. when it comes to date/time-values.
So, e.g. I would use something like
Code: Select all
SELECT *, (dtCreated < Now() - interval 3 day) as isNew from tableNamewhere
isNew contains 1 if
dtCreated is less than 3 days in the past and 0 otherwise.
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Tue Feb 18, 2003 5:25 pm
twigletmac wrote: You need to have some sort of test that takes the timestamp from the database, compares it to the current timestamp and if the difference is within a particular timeframe, display the 'new' image and if not don't.
Mac
Thanks Mac!
Is this the cort of code I need:
Code: Select all
<?php
$s_time = $timestamp;
$e_time = $timestamp + 86400;
$getnew = mysql_fetch_array(mysql_query("select from links where uptime > $s_time and uptime < $e_time""));
?>
Thanks!
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Wed Feb 19, 2003 5:54 pm
Can't wait till I work this out
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Feb 19, 2003 8:24 pm
e.g.
Code: Select all
<html><body><table>
<?php
$intervalNew = 3;
$dbCon = mysql_connect( ... ) or die(mysql_error());
mysql_select_db( ... , $dbCon) or die(mysql_error());
$query = 'SELECT *, (uptime > Now() - interval '.$intervalNew.' day) as isNew from links';
$result = mysql_query($query, $dbCon) or die(mysql_error());;
while ($row = mysql_fetch_array($result))
{
echo '<tr><td>', ($row['isNew']) ? 'new</td>': '</td>';
foreach($row as $value)
echo '<td>', $value, '</td>';
echo '</tr>';
}
?></table></body>