Support Forums

Old 08-27-2008, 09:54 AM   #1
Senior Member
 
 
Join Date: Sep 2006
Location: USA
Posts: 116
Rep Power: 14
BigOrange will become famous soon enough
Default Help calling Extra Field in function.new_listing.php

I have setup an extra field named "Item Location". I want to show that in the plugin function.new_listing.php.

I can show the city they listed when they signed up with the code below, but I want to show the city where the item is physically located by using the Extra field "Item Location". How do I replace [city] with the extra field in the code below?

Thanks!

PHP Code:

// city
$output.=$loop[$x][city].")</span></center>"
Below is the entire code for function.new_listing.php.

PHP Code:

<?php
/**
* smarty_function_new_listings
*
* This function is useful for generating a vertical table of new listings.
*
* All source code & content (c) Copyright 2006, 68 Classifieds
* unless specifically noted otherwise.
*
* @package 68classifieds
* @author  Eric Barnes
* @copyright 68 Classifieds
* @link http://www.68classifieds.com
* @$Revision: 1.3 $
* @Updated: $Date: 2006/05/26 13:14:08 $
*/
function smarty_function_new_listings($params, &$smarty)
{
    global 
$db;

    
$table_attr 'border="1"';
    
$tr_attr '';
    
$td_attr '';
    
$number=4;
    
$trailpad ' ';
    
$img_break '<br />';
    
$date_format '%B %e, %Y %I:%M %p';

    foreach (
$params as $_key=>$_value)
    {
        switch (
$_key)
        {
            case 
'number':
                $
$_key = (int)$_value;
                break;

            case 
'table_attr':
            case 
'img_break':
            case 
'date_format':
                $
$_key = (string)$_value;
                break;

            case 
'tr_attr':
            case 
'td_attr':
                $
$_key $_value;
                break;
        }
    }

        
$sSQL="SELECT p.id, p.owner, p.title, p.featured, p.section, p.description, p.price, p.dateadded, p.expiration, p.pHighlighted, p.pBold, u.state, u.city, u.country FROM ".PREFIX."products AS p LEFT JOIN ".PREFIX."users AS u ON p.owner = u.id WHERE p.expiration > NOW() AND p.display = 'Y' ORDER BY p.dateadded DESC LIMIT ".$number;
        
$result=$db->query($sSQL);
        
$i=0;
        while(
$row=$result->fetch())
        {
            
//added by eric//
                
$imageSQL "SELECT image FROM ".PREFIX."prodimages WHERE pid=".$row['id']." ORDER BY rank LIMIT 1";
                        
$iResult=$db->query($imageSQL);
                        
$irs=$iResult->fetch();
                        if(
$irs['image']<>"")
                        {
                             
$image=TRUE;
                        }
                        else
                        {
                             
$image="";
                        }
            
//end added by eric//
            
$tmp = array(
                
'id' => $row['id'],
                
'title'=> $row['title'],
                
'city'=> $row['city'],
                
'state'=> $row['state'],
                
'dateadded'=>$row['dateadded'],
                
'price'=> FormatCurrency($row['price']),
                
'image'=>$image
                
);
                
$loop[$i++] = $tmp;
        }
    
$loop_count count($loop)-1;

    
$output "<table " $table_attr.">\n";
    for (
$x 0$x<= $loop_count$x++)
    {
        
//opening tr
        
$output .= "<tr" smarty_function_html_table_cycle_newlistings('tr',   $tr_attr$c) . ">\n";
        
//opening td
        
$output .= "<td class=\"newlist\"" smarty_function_html_table_cycle_newlistings('td',   $td_attr$c) . ">\n";
            
//title
            
if(defined('SEO'))
            {
                
$listing_title=$loop[$x][title];
                
$listing_title=str_replace(' ''_'$listing_title);
                
$listing_title=preg_replace('/\W/e'''$listing_title);
                
$output.="<a href='listing/".$loop[$x][id]."/".$listing_title.".html'>".$loop[$x][title]."</a>";
            }

            
// This is being used RLB
            
else
            {
             
// Check for photo in ad by RLB
               
if ($loop[$x][image] != "")
               {
                  
$output.="<img src='/templates/default/images/ico_has_photo.jpg' align='left' width='14'>  ";
               }
              else
              {
                  
$output.=" ";
              }
            
// END Check for photo in ad by RLB

              //ad title
              
$output.="<a href='viewlisting.php?view="$loop[$x][id] ."'>".$loop[$x][title]."</a>  ";
            }

              
//price
              
$output.="<center>"."<span style='font-size: 10px; color: #000000;'>".$loop[$x][price]."   (";

              
//date
              //$output.=smarty_modifier_date_format($loop[$x][dateadded], $date_format);

             // I want to change this to the extra field: "Item Location".
             // city 
              
$output.=$loop[$x][city].")</span></center>";

              
// city
              // $output.=$loop[$x][state].")";

              //closing td
              
$output.="</td>\n";
              
$output .= "</tr>\n";
    }
    
$output .= "</table><br />\n";

    return 
$output;
}

function 
smarty_function_html_table_cycle_newlistings($name  $var$no)
{
    if(!
is_array($var))
    {
        
$ret $var;
    }
    else
    {
        
$ret $var[$no count($var)];
    }
    return (
$ret) ? ' '.$ret '';
}

?>
__________________
V3.1.5 Designer

"I have not failed. I've just found 10,000 ways that won't work."
THOMAS ALVA EDISON
BigOrange is offline   Reply With Quote
Old 08-27-2008, 10:03 AM   #2
Coder
 
Join Date: Mar 2006
Posts: 4,567
Rep Power: 111
Lhotch is just really niceLhotch is just really nice
Default

Extra fields are a whole different can of worms. Since extra fields can apply to only certain categories they are actually housed in 3 different tables.

class_fields
class_fields_bindings
class_fields_options

Your going to have to create a whole new query, joining some of the above tables to get the value of the extra field you need so you can place it in the plugin. Your best bet would be to look at the code that pulls up the extra fields and the field contents for viewlisting.
__________________
Larry.
Lhotch is offline   Reply With Quote
Old 08-27-2008, 10:13 AM   #3
Senior Member
 
 
Join Date: Sep 2006
Location: USA
Posts: 116
Rep Power: 14
BigOrange will become famous soon enough
Default

The code below is what pulls the extra fields in viewlisting.php. I'm not good at php but the code seems to output ALL the extra fields. How can I modify it to only pull one specific field: "Item Location"?

I really appreciate the help!


PHP Code:

{/if}
            {* 
Extra Fields *}
            {foreach 
from=$extra item=extras}
            <
tr>
                <
td valign="top" width="250">{$extras.title}:</td>
                <
td>
                    {if isset(
$extras.value)}
                      {foreach 
key=key item=item from=$extras.value}
                        {
$item}<br />
                      {/foreach}
                     {/if}
                </
td>
            </
tr>
            {/foreach}
            {* 
End Extra Fields *} 
__________________
V3.1.5 Designer

"I have not failed. I've just found 10,000 ways that won't work."
THOMAS ALVA EDISON
BigOrange is offline   Reply With Quote
Old 08-27-2008, 10:29 AM   #4
68 Classifieds Staff
 
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,125
Rep Power: 118
Eric Barnes is a jewel in the rough
Default

No that is actually just looping through the array that the php file generated. In v3.1.x I think you need to look at viewlisting.php and find the //extra fields section.
__________________
Eric Barnes
68 Classifieds Developer
Please do not send me a private message asking for support. Instead use these open forums or our ticket system.

Customer Area | Issue Tracker | Documentation | 68C Mods | Submit a Ticket | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 08-27-2008, 12:05 PM   #5
Senior Member
 
 
Join Date: Sep 2006
Location: USA
Posts: 116
Rep Power: 14
BigOrange will become famous soon enough
Default

Is it possible to get the extra field I want from the code in my last post by maybe using the extra field ID# or some other way? I only have the designer edition and I can't view the viewlisting.php file.
__________________
V3.1.5 Designer

"I have not failed. I've just found 10,000 ways that won't work."
THOMAS ALVA EDISON
BigOrange is offline   Reply With Quote
Old 08-27-2008, 01:22 PM   #6
Coder
 
Join Date: Mar 2006
Posts: 4,567
Rep Power: 111
Lhotch is just really niceLhotch is just really nice
Default

Quote:
Originally Posted by BigOrange View Post
Is it possible to get the extra field I want from the code in my last post by maybe using the extra field ID# or some other way? I only have the designer edition and I can't view the viewlisting.php file.
The code in the plugin you listed doesnt even query the extra field tables so the extra field data isnt even pulled from the database.
__________________
Larry.
Lhotch is offline   Reply With Quote

Bookmarks

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort order by extra field HotAir v3.1 Modules & Modifications 3 02-11-2008 11:03 AM
admin > category > extra fields info disappearing kgrinsteiner v3.1 Questions & Support 0 12-16-2007 07:27 PM
Extra Search Field Greg H v3.1 Modules & Modifications 2 10-04-2007 12:04 AM
Adding extra field to search.php... abkeller v3.1 Modules & Modifications 4 06-05-2007 12:15 AM
listing extra field value when it is an array? Mike-N-Tosh v3.1 Modules & Modifications 13 04-21-2007 09:31 AM


All times are GMT -4. The time now is 03:51 AM.


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