Page 1 of 2

A couple questions

Posted: Sun Feb 16, 2003 4:49 pm
by Mr. Tech
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 :P

Posted: Sun Feb 16, 2003 7:38 pm
by volka
1) define new ;)
2) "SELECT count(*) tablename" optional "SELECT count(*) tablename WHERE condition"

Posted: Sun Feb 16, 2003 8:55 pm
by Mr. Tech
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!

Posted: Sun Feb 16, 2003 9:21 pm
by volka
I just wanted to know what you mean with new.
1 day old, 3, not seen by the user before, marked as new, ...

Posted: Sun Feb 16, 2003 9:27 pm
by Mr. Tech
Oh, sorry(I thought that was code) :oops:

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 :D

Posted: Sun Feb 16, 2003 11:47 pm
by volka
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.

Posted: Mon Feb 17, 2003 1:30 am
by Mr. Tech
I amy using mySQL.

Posted: Mon Feb 17, 2003 4:28 am
by Mr. Tech
twigletmac answered everyones questions except mine! Thanks for any help :o !

Posted: Mon Feb 17, 2003 4:52 am
by twigletmac
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

Posted: Mon Feb 17, 2003 6:47 pm
by Mr. Tech
When I add the links to the DB I insert these two:

now()
time()


Are they what I need? Thanks for replying :D

Posted: Tue Feb 18, 2003 2:20 am
by twigletmac
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

Posted: Tue Feb 18, 2003 3:07 am
by volka
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 tableName
where isNew contains 1 if dtCreated is less than 3 days in the past and 0 otherwise.

Posted: Tue Feb 18, 2003 5:25 pm
by Mr. Tech
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!

Posted: Wed Feb 19, 2003 5:54 pm
by Mr. Tech
Can't wait till I work this out :P

Posted: Wed Feb 19, 2003 8:24 pm
by volka
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>