8 – How do I create a select field that looks up values from a database?

How would I go about setting up a ‘lookup’ function to essentially allow a user to select values from a select or dropdown field (for example), where these values are stored in a database?

I know my way around the Webform module to a decent level, but I cannot see any option/setting to set up this kind of functionality, given it is quite a common requirement for forms.

The Add webform option isn’t something I can use, as there are numerous values, too many to enter manually.

entities – Create Custom Select Webform Element

I asked this last time with ‘Select Other’, but I am still not understanding how to change custom element’s type. In this scenario, I am attempting to build a Select type webform element. I am reusing the Webform Example attached to the webform module. But my issue is that I can not change it from an <input> to a <select> type.

Inside, webform_example_elementsrcElementWebformExampleElement.php I have tried:

  public function getInfo() {
    $class = get_class($this);
    return (
      '#title' => $this->t('Facility'),
      '#type' => 'Select',
      '#input' => false,
    ...
   }

AND I have tried:

  public static function processWebformAssignedBy(&$element, FormStateInterface $form_state, &$complete_form) {
    $element('#tree') = true;
    $element('#type') = 'select';
    $element('#input') = false;
    $element('#options') = (
      '1' => 'One',
      '2' => 'Two',
    );

Using X-Debug, when the page is loaded I get:

$element = {array} (48)
 #type = "select"
 #title = "current_facility"
 #multiple = false
 #access_create_roles = {array} (2)
 #access_update_roles = {array} (2)
 #access_view_roles = {array} (2)
 #webform = "generate_system_number_form_1_"
 #webform_id = "generate_system_number_form_1_--current_facility"
 #webform_key = "current_facility"
 #webform_parent_key = "net_new_process_information"
 #webform_parent_flexbox = false
 #webform_depth = {int} 1
 #webform_children = {array} (0)
 #webform_multiple = false
 #webform_composite = false
 #webform_parents = {array} (2)
 #admin_title = "current_facility"
 #webform_plugin_id = "facility"
 #webform_submission = "121"
 #access = true
 #webform_element = true
 #allowed_tags = {array} (78)
 #element_validate = {array} (1)
 #pre_render = {array} (1)
 #after_build = {array} (1)
 #_webform_access = true
 #_webform_states = {array} (0)
 #theme = "input__webform_example_element__webform_generate_system_number_form_1__form__current_facility"
 #theme_wrappers = {array} (1)
 #formdazzle = {array} (3)
 #process = {array} (3)
 #input = false
 #value_callback = {array} (2)
 #defaults_loaded = true
 #tree = true
 #parents = {array} (1)
 #array_parents = {array} (3)
 #weight = {float} 0.007
 #processed = false
 #required = false
 #attributes = {array} (1)
 #title_display = "before"
 #description_display = "after"
 #errors = null
 #id = "edit-current-facility"
 #name = "current_facility"
 #value = ""
 #options = {array} (2)

But after returning, I still get an <input> field. Any suggestions how to alter the input type to be select? Thank you

java – Unable to get the dynamically created Select tags values which are created using Javascript (xml, xsl)transform

this is my index.jsp page index.jsp where i created two dropdowns from script

<body>
    <jsp:useBean id="po" scope="request" class="Forms.POInfoForm" />
    <form name="frmEntry" method="post" accept-charset="utf-8" action="mediator.jsp" onSubmit = "return confirmSubmit();">
    <table border="3" bordercolor="#000000" id="tableName2" width="80%"> 
        <%  
        if (po.getBldgId() != null) {
            for (int j=0; j < po.getBldgId().length; j++) { 
            %>
                            
                            <input type="hidden" value="" name="bldgitemId">
                            <tr>
                                <td width="33%">
                                    <font color="#000000">  Building: </font>
                                    <div id="buildingInfo<%=j%>"/>
                                    <script language="JavaScript">
                                
                              createBuildingList(<%=j%>, buildingInfo<%=j%>, <%=po.getBldgId(j) %>);
                                    </script>

                            <td width="33%">
                                <font color="#000000">  Sub Account: </font>
                                <div id="subAccountInfo<%=j%>"/>
                                <script language="JavaScript">
createSubAccountList(<%=j%>, subAccountInfo<%=j%>, <%=po.getBldgId(j) %>, <%=po.getSubAccountId(j) %>);
                                
                            </script>
                             </td>
                             </tr>
                           </table>

after clicking the submit the request will go to another jsp page called mediator.jsp, where i am checking the values.

mediator.jsp

<html>
<head>
<title>
Mediator
</title>
</head>
<jsp:useBean id="po" scope="request" class="Forms.POInfoForm" />
<body bgcolor="#ffffff">
<h1>
Mediator JSP
</h1>
<%System.out.println("bldgId is-->"+request.getParameter("bldgId")); %>
<%System.out.println("subAccoutId is-->"+request.getParameter("subAccountId")); %>
//some actions 

below is the two select tags with values generated from the index.jsp page.

image inspecting index.jsp

enter image description here

Note: i am able to fetch the above two select tag values in IE but not in Edge,Chrome, please help me,
Thanks in Advance!..

8 – Form API placeholder attribute rendered as “- Select -“

In a custom Drupal 8 module, I have a couple of Form API fields of '#type' => 'select':

<?
    $form('form-right')('field_role') = (
      '#type' => 'select',
      '#title' => $this->t('Role'),
      '#title_display' => 'invisible',
      '#required' => TRUE,
      '#options' => (
        'foo' => $this->t('Role Foo'),
        'bar' => $this->t('Role Bar'),
        'baz' => $this->t('Role Baz'),
        'quux' => $this->t('Role Quux'),
        'plugh' => $this->t('Role Plugh'),
        'xyzzy' => $this->t('Role Xyzzy'),
      ),
      '#attributes' => (
        'placeholder' => $this->t('Role'),
      ),
    );

    $form('form-right')('field_contact_reason') = (
      '#type' => 'select',
      '#title' => $this->t('Contact Reason'),
      '#title_display' => 'invisible',
      '#required' => TRUE,
      '#options' => (
        'foo' => $this->t('Contact Reason Foo'),
        'bar' => $this->t('Contact Reason Bar'),
        'baz' => $this->t('Contact Reason Baz'),
        'other' => $this->t('Other'),
      ),
      '#attributes' => (
        'placeholder' => $this->t('Contact Reason'),
      ),
    );

Before a value is selected, the dropdown select picklists display the string '- Select -':

Form API placeholder attribute rendered as "- Select -"

The client would like them to display the value in the placeholder attribute instead.

Have I done something wrong?

is it possible to select items in page and order by drag and drop them in another page in a multi pages form

As in https://www.drupal.org/project/webform/issues/3037186

i’m asking the same request here as suggested in the issue

On Drupal8 and Webform, is there a way to have something like that :

  • user chooses X items in a list ;
  • he can order those X items by drag and drop ?

grant select in just one DMV instead of grant VIEW SERVER STATE

I think you can wrap the select against the specific DMV in a stored procedure and then use Execute As to elevate the permissions.

whether you choose to sign the SP with a certificate, execute as SA or as Owner is something you will need to determine according to your own security needs.

performance tuning – Why is doing a computation inside Select slower than a precomputation?

I am trying to generate primitive Pythogorean triples using Euclid’s parametrization. I basically want a list of pairs with ordered pairs $(m,n)$ such that $m$ and $n$ are coprime.

My first approach was

AbsoluteTiming(
 list1 = Flatten(Table({m, n}, {m, 1, 20000, 2}, {n, 2, 20000, 2}), 1);
 list2 = Select(list1, (GCD(#((1)), #((2))) == 1) &);)

(*{223.175, Null}*)

in which I first produce a list of pairs where $m$ is always odd and $n$ is always even. Then I use Select to select the pairs where both coordinates are coprime. I quit and restarted a local kernel with a simple computation like 2+2 to make sure there are no effects due to caching, garbage cleanup, or something like that. I then timed the whole thing and got 223 seconds.

My second approach was

AbsoluteTiming(
 list1 = Flatten(
   Table({m, n, GCD(m, n)}, {m, 1, 20000, 2}, {n, 2, 20000, 2}), 1);
 list2 = Select(list1, #((3)) == 1 &);)

(*{161.464, Null}*)

in which I compute a third column inside the Table which is the GCD of $m$ and $n$. Then I used Select to simply pick the lists where the third coordinate is one. Restarting the kernel as before and timing it gives me only 161 seconds, which is almost 40% faster.

Why is the first method slower? I don’t care about the memory usage. Obviously storing the third column will take more memory.

My thoughts,

  • I would expect both of them to take roughly the same amount of time. If anything, I would expect the second approach to be slower. We are flattening an array with more elements.
  • They are both vectorized approaches.
  • The kernel is doing all of the work (instead of the front-end) in both cases.
  • The number of GDC operations is the same in both cases.
  • The number of comparisons is the same in both cases.
  • In the first case, Select is scanning row-by-row, computing the GCD, and comparing it to one.
  • In the second case, Table is computing the GCD row-by-row and Select is only scanning the third column and comparing it to one.

Which of these, if any, is wrong? The only thing I can think of is that in the first approach Select is scanning both the first and the second column. In the second approach Select is only concerned with the third column ignoring the first two columns completely. Is this true?

What is going on here? What are the lesson to be learned here, in the context of writing fast MMA code?

neomutt – Saving an attachment in Mutt – how to select a directory using the list view

Browse to the directory ~/a/b/c and then use N to save as a new file in that directory.

You can then either type a file name, or if you want to save under the name that the attachment has, simply hit return: You’ll be prompted “File … is a directory, save under it?” which defaults to yes, so you can hit return again. Then mutt offers to save as ~/a/b/c/name_of_attachment

MySQL: Why am I getting a syntax error when using the FIELDS ESCAPED BY clause on a select statement

I am attempting to generate a csv file including headers from a table in my MySQL 8.0 database. After a lot of searching I found the following suggest syntax:

    SELECT "ansId","assmt","ques","answerCode","details"
    FROM ayanswer
    UNION
    SELECT ansId,assmt,ques,answerCode,details
    FROM ayanswer
    INTO OUTFILE 'c:/data/test1.csv'
    FIELDS TERMINATED by ','
    OPTIONALLY ENCLOSED BY '"'
    FIELDS ESCAPED BY '\';

However when I run this statement in mysql I get the following error:
ERROR 1064 (42000) at line 1: 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 ‘FIELDS ESCAPED BY ”’ at line 9

According to the MySQL Server 8.0 reference manual this syntax should be correct. So what am I doing wrong?

sql server – Como dar um select em uma determiada linha consultando pela posição

Tenho um script que pega a primeira linha da consulta,mas gostaria que ele pegasse a 5 linha sem especificar no where qual eu quero, ir pela posição mesmo, como faço? É possível?