A couple questions

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

A couple questions

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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 »

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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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, ...
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

I amy using mySQL.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

twigletmac answered everyones questions except mine! Thanks for any help :o !
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post 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!
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Can't wait till I work this out :P
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
Post Reply