Support Forums

Show the visitors which category has new ads

This is a discussion on Show the visitors which category has new ads within the v3.1 Modules & Modifications forums, part of the Legacy Help & Support category; If a visitor hits the "New Listings" link, he'll get a list of the latest ads from all categories. I ...


Go Back   68 Classifieds Forums > Archives > Legacy Help & Support > v3.1 Modules & Modifications

 
 
Thread Tools Display Modes
Old 07-20-2006, 01:41 PM   #1
Senior Member
 
pat01's Avatar
 
Join Date: Jun 2006
Location: Switzerland
Posts: 102
Rep Power: 17
pat01 is on a distinguished road
Default Show the visitors which category has new ads

If a visitor hits the "New Listings" link, he'll get a list of the latest ads from all categories. I think it would be very helpfull for the users if they can see right away which category has new ads.

On the index.php, all the categories and subcategories are displayed. How about if behind the name of each category which has new ads a "NEW" sign would be displayed? The "NEW" can be as text or an image.

I did try it but now I'm stuck...

I don't know how to calculate the date and time correctely and how to assign these information to each category. Maybe somebody has a solution for this?

And here is what I did in index.php:

PHP Code:
# START FUNCTION SHOW NEW 
$sSQL3 ="SELECT id, dateadded FROM ".PREFIX."products WHERE id=".$rs['id'];
        
$result3=$db->query($sSQL3);
        
$newads=$result3->fetch();

$new="NEW ads!";

# $timeframe = "24";  // Not used yet, this value tells for how many hours an ad is 'new' = from now minus $new the $newmessage is shown behind the category name. For testing I use the -1 below.

$now mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$adsdate $newads['dateadded'];
$strip substr($adsdate,0,10);

if(
$strip $now) {
$newmessage $new;
}
else
                {
$newmessage "";
                }

# END FUNCTION SHOW NEW 

And I added '.$newmessage.'

to
$add_cats.='<a href="category.php?type='.$rs['id'].'&sec='.$arow['id'].'">'.$arow['name'].'</a> ';


What do you think about this feature?
Any help would be appreciated, thank you very much!
__________________
v4.1.6 dev, Default Template
I say: Mooooh...!
pat01 is offline  
Old 07-20-2006, 01:51 PM   #2
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,266
Rep Power: 124
Eric Barnes is a jewel in the rough
Default

I think you are on the right track but I would do it a different way.

Since on the index page you already know the category you could change your query to something like this:
PHP Code:
$yesterday date('Y-m-d'mktime(000date("Y") , date("m"), date("d") - 1));
$sSQL="SELECT id FROM ".PREFIX."products WHERE section=".$sectionid." AND dateadded >= '".$yesterday."' AND active='Y'"
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline  
Old 07-20-2006, 03:39 PM   #3
Senior Member
 
pat01's Avatar
 
Join Date: Jun 2006
Location: Switzerland
Posts: 102
Rep Power: 17
pat01 is on a distinguished road
Default

No matter what I do, I get the following error:

Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND dateadded >= '1969-12-31' AND active='Y'' at line 1 SQL: SELECT id FROM class_products WHERE section= AND dateadded >= '1969-12-31' AND active='Y'

Any idea? OK, the section= is empty... is that supposed to be like that?
__________________
v4.1.6 dev, Default Template
I say: Mooooh...!
pat01 is offline  
Old 07-20-2006, 05:15 PM   #4
Moderator
 
juven14's Avatar
 
Join Date: Mar 2006
Location: Texas
Posts: 1,961
Rep Power: 58
juven14 is a jewel in the rough
Default

Should $sectionid be $section?

Maybe arow['id']?
__________________
John Snyder
PHP Developer

Last edited by juven14; 07-20-2006 at 05:18 PM.
juven14 is offline  
Old 07-21-2006, 01:53 AM   #5
Senior Member
 
pat01's Avatar
 
Join Date: Jun 2006
Location: Switzerland
Posts: 102
Rep Power: 17
pat01 is on a distinguished road
Default

I guess it has more likely to do with the date:
AND dateadded >= '1969-12-31' AND active='Y

I'm wondering about 1969-12-31 ?

EDIT: I changed the $yesterday to:
$yesterday = date('Y-m-d', mktime(0,0,0,date("m"),date("d")-1,date("Y")));

Now I get the correct date, but still a SQL error. I guess there is a typo in the query?

EDIT2: Guess I found it. Changed the query to
$sSQL="SELECT id FROM ".PREFIX."products WHERE section='".$sectionid."' AND dateadded >= '".$yesterday."' AND display='Y'";

At least no more SQL errors
__________________
v4.1.6 dev, Default Template
I say: Mooooh...!

Last edited by pat01; 07-21-2006 at 03:00 AM.
pat01 is offline  
Old 07-21-2006, 04:35 AM   #6
Senior Member
 
pat01's Avatar
 
Join Date: Jun 2006
Location: Switzerland
Posts: 102
Rep Power: 17
pat01 is on a distinguished road
Default

Quote:
Originally Posted by juven14
Maybe arow['id']?
That did the trick, thanks!

Finally, it works:

PHP Code:
$yesterday date('Y-m-d'mktime(0,0,0,date("m"),date("d")-1,date("Y")));
$sSQL="SELECT id FROM ".PREFIX."products WHERE section='".$arow['id']."' AND dateadded >= '".$yesterday."' AND display='Y'"
        
$result3=$db->query($sSQL);
        
$newads=$result3->fetch();
        
$new="NEW ads!";
if(
$newads 0) {
    
$newmessage $new;
}
else    {
    
$newmessage="";


The only problem is, that I can define to show the $newmessage in days only, not in hours. I can't define show me the $newmessage if an ad is newer than 5 hours. At least, the above function is a start...

Maybe somebody has an idea how to improve this?
__________________
v4.1.6 dev, Default Template
I say: Mooooh...!
pat01 is offline  
Old 07-21-2006, 09:59 AM   #7
Senior Member
 
pat01's Avatar
 
Join Date: Jun 2006
Location: Switzerland
Posts: 102
Rep Power: 17
pat01 is on a distinguished road
Default

OK, here it is:

PHP Code:
$timeframe "12"# Max. age of a new ad in hours

$timecalc date("Y-m-d H:i:s"time()-(($timeframe)*(3600)));

$sSQL="SELECT id,dateadded FROM ".PREFIX."products WHERE section='".$arow['id']."' AND dateadded >= '".$timecalc."' AND display='Y'"
        
$result3=$db->query($sSQL);
        
$newads=$result3->fetch();

$new="NEW ads!";

if(
$newads 0) {
    
$newmessage $new;
}
else    {
    
$newmessage="";

I'm still testing it, but so far it looks good.

Maybe somebody can tell me how to integrate this function into the category.php with subcategories.tpl.php and showlistings.tpl.php? They have a different code, I guess I must write something like [[newmessage]] into subcategories.tpl.php and {$newmessage} into showlistings.tpl.php? But what needs to be changed in the function itself?
__________________
v4.1.6 dev, Default Template
I say: Mooooh...!

Last edited by pat01; 07-21-2006 at 12:28 PM.
pat01 is offline  
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding 'category' to 'new listings' display Chaslie v3.1 Modules & Modifications 5 01-31-2008 04:31 PM
Show name of category in viewlisting HotAir v3.1 Questions & Support 4 01-08-2007 04:59 PM
Show customers URL on showlistings.tpl.php marketingsolutions v3.1 Questions & Support 0 11-01-2006 09:38 PM
Category problem dawyatt v3.1 Questions & Support 2 05-24-2006 04:58 PM


All times are GMT -4. The time now is 07:31 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0