68 Classifieds Forums
Go Back   68 Classifieds Forums > v3.0.x Help & Support > v3.0 Modifications > Display Total Number of Listings
 
Thread Tools Search this Thread Display Modes
(#1)
suzkaw suzkaw is offline
Staff
suzkaw is on a distinguished road
 
Posts: 1,232
Join Date: Mar 2006
Location: Belmont, NC
Default Display Total Number of Listings - 03-30-2006, 08:49 AM

Here is a smarty function to display the total number of listings.
  1. Copy and paste this code in a new file and save it as: function.total_listings.php
  2. Next upload it to includes/templates/plugins/ directory
  3. Finally to display the total add {total_listings} to your template file.
Here is the code:

PHP Code:
<?php
/**************************************************  *********************
| 68 Classifieds developed by 68 Designs, LLC.
|-----------------------------------------------------------------------
| All source code & content (c) Copyright 2005, 68 Designs LLC
|   unless specifically noted otherwise.
|
|The contents of this file are protect under law as the intellectual property
| of 68 Designs, LLC. Any use, reproduction, disclosure or copying
| of any kind without the express and written permission of 68 Designs, LLC is forbidden.
|
| __________________________________________________  ____________________
|    http://www.68classifieds.com      http://www.68designs.com/
**************************************************  *********************/
function smarty_function_total_listings($params, &$smarty)
{
    global
$db;
    
    
//get total active listings
    
$sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."products WHERE expiration > NOW() AND display = 'Y'";
    
$result=$db->query($sSQL);
    
$rs=$result->fetch();
    
$total_listings=$rs['total'];

    return
$total_listings;
}
?>


--
Thanks,
Eric Barnes
68 Classifieds

Documentation - Bug Reports - Modifications - My Blog
(#2)
free2take's Avatar
free2take free2take is offline
Senior Member
free2take is on a distinguished road
 
Posts: 103
Join Date: Mar 2006
Location: Ireland
Send a message via Yahoo to free2take
Default 03-30-2006, 02:06 PM

Similar type function I wrote is count_user_field.

May be of use to someone else out there also, I needed a custom function to display how many listings had an admin defined extra field set to a certain value in my case the field was 'Status' and the value was 'Reused' you can pass any extra field and value to the function though.

PHP Code:
<?php
function smarty_function_count_user_field($params, $smarty)
{
    global
$db;
    
        foreach (
$params as $_key=>$_value)
    {
        switch (
$_key)
        {
            case
'fldname':
                $
$_key = (string)$_value;
                break;
            case
'fldvalue':
                $
$_key = (string)$_value;
                break;
        }
    }

    
//Get field ID from class_fields
    
$sSQL = "SELECT fID FROM ".PREFIX."fields WHERE fNAME = '$fldname'";
    
$result=$db->query($sSQL);
    
$fID=$result->fetch();
    
//Count number of ads with field set to desired status
    
$sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."products,".PREFIX."products_fields WHERE id=pID AND expiration > NOW() AND display = 'Y' AND sValue = '$fldvalue'";
    
$result=$db->query($sSQL);
    
$rs=$result->fetch();
    return
$rs['total'];
}
?>

Copy and paste this code in a new file and save it as: function.count_user_field.php
Upload it to includes/templates/plugins/ directory
Finally to display the total add {count_user_field fldname=YourExtraFieldName fldvalue=YourFieldsValue} to your template file.

In my case call was;
{count_user_field fldname=Status fldvalue=Reused}

Hope it helps all the best,
Mully
(#3)
suzkaw suzkaw is offline
Staff
suzkaw is on a distinguished road
 
Posts: 1,232
Join Date: Mar 2006
Location: Belmont, NC
Default 03-30-2006, 02:29 PM

Very nice!


--
Thanks,
Eric Barnes
68 Classifieds

Documentation - Bug Reports - Modifications - My Blog


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display Total Number of Users suzkaw v3.0 Modifications 5 05-10-2006 11:22 AM
Year quickbiz v3.0 Modifications 2 04-21-2006 07:20 AM
Area to display # of members and # of ads zman78 Template Design Questions 13 03-30-2006 08:51 AM



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2006, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com