Help Dropdown Code

Hello everybody,
i need to customize a dropdown from the Opportunities module.
Dropdown values will come from another table Tab1 (that is costantly updating) and i want to show them depending on other opportunity fields.

EXEMPLE:
Opportunities -> NAME: ‘123’ | SERIAL NUMBER: ‘XYZ’ | PRODUCT: ‘pizza’
Tab1 -> VALUE: ‘pasta’ | OPPORTUNITY NAME: ‘123’ | SERIAL NUMBER: ‘XYZ’
VALUE: ‘pizza’ | OPPORTUNITY NAME: ‘123’ | SERIAL NUMBER: ‘XYZ’
VALUE: ‘ice cream’ | OPPORTUNITY NAME: ‘123’ | SERIAL NUMBER: ‘XYZ’

So…in the dropdown i need, i would select from 3 values, pasta, pizza, icecream.
In your opinion is that possible?
Thank you so much :cheer:

Try this technique

https://web.archive.org/web/20140116145925/http://www.eggsurplus.com/home/content/populate-a-dropdown-from-the-database/

it seems to work, but when i try to add some conditions to the query it goes to error.
I toke a bean from the opportunities module and i’ve to insert a opportunity field in the queri condition ‘where’.

this is the function php, do you see some errors?
:unsure: :unsure:


<?php
function getRenewalSku(){
    static $renewalSku = null;
    $beanOpportunity = BeanFactory::getBean('Opportunities');

    if(!$renewalSku){
        global $db;



        $query = "SELECT techdata_renewals.32, techdata_renewals.19 FROM techdata_renewals where techdata_renewals.19 like '%switch%' and techdata_renewals.26 = " . $beanOpportunity->li_serial_number_c . " group by techdata_renewals.26 order by techdata_renewals.19 asc";

        $result = $db->query($query, false);

        $renewalSku = array();
        $renewalSku[''] = '';

        while (($row = $db->fetchByAssoc($result)) != null) {
            $renewalSku[$row['techdata_renewals.32']] = $row['techdata_renewals.19'];
        }

    }
    return $renewalSku;
}
 ?>

PS i execute the query with the $beanOpportunity->li_serial_number_c value manually and it works

You should have a MySql error in your web server log, normally it’s called php_errors.log or errors.log

You can also try checking the returned $result for errors.

Nothing.
That is freaking me out .
RECAP: I’ve a custom field in the module Opportunities that i set up as a custom dropdown that runs a query from mySql db.
This field and the query go well if i do not insert the condition that comes from the bean variable.

OK? NO! :oops:

Infact i just want that the query gives me results depending on the opportunity i’m in.
How can i execute the query keeping a field in Opportunities and using this as a variable in where condition?

following is not workingg :frowning:


<?php
function getRenewalSku(){
    static $renewalSku = null;
    if(!$renewalSku){
        global $db;
        require_once 'data/BeanFactory.php';
        $bean = BeanFactory::getBean(Opportunities);
        $serialNumber = $bean->li_serial_number_c;
        $query = "SELECT Renewal_SKU, Renewal_Number FROM techdata_renewals where Renewal_Number like '%switch%' and Serial_Number = '".$serialNumber."' order by Renewal_Number asc";
        $result = $db->query($query);
        $renewalSku = array();
        $renewalSku[''] = '';
        while (($row = $db->fetchByAssoc($result)) != null) {
            $renewalSku[$row['Renewal_SKU']] = $row['Renewal_Number'];
        }
    }
    return $renewalSku;
}
 ?>

:S :S :S
Thank you so much, i hope there’s somebody that can help me

P.S. I can’t find any log php_error neither mysql.log

Please make yourself a favor and find the other log :slight_smile:

IT’s your web server log. So get your web server name (Apache? Nginx? IIS?) and go to StackOverflow and find out where your log is. It’s defined in one of the configuration files. You need that information to develops successfully.

Instead of “it doesn’t work” you should be knowing that you have a missing parenthesis or something, a specific problem.

Have you tried:

$bean = BeanFactory::getBean('Opportunities');

instead of:

$bean = BeanFactory::getBean(Opportunities);

(please note that I added two quotes around the word Opportunities)

Hi everybody, I DID IT! :woohoo: :woohoo: :woohoo: :woohoo:
Finally i made it.
I was wrong using the $this call, because i’m in a global method.
I had to use $GLOBALS[‘app’][‘bean’][‘id’] to find the bean id of the opportunity.
This is the correct code:


<?php
function getRenewalSku(){
    static $renewalSku = null;
    if(!$renewalSku){
        global $db;
        $bean = $GLOBALS['app']->controller->bean;
        $serialNumber = $bean->li_serial_number_c;
        $query = "SELECT Renewal_SKU, Renewal_Number FROM techdata_renewals where Renewal_Number like '%switch%' and Serial_Number = '".$serialNumber."' group by Renewal_Number order by Renewal_Number asc";
        $result = $db->query($query);
        $renewalSku = array();
        $renewalSku[''] = '';
        while (($row = $db->fetchByAssoc($result)) != null) {
            $renewalSku[$row['Renewal_SKU']] = $row['Renewal_Number'];
        }
    }
    return $renewalSku;
}
 ?>

Anyway i have to thank you guys too for the helpfull advises
B-)

1 Like