Select

javascript – Auto select dependent dropdown with jquery json


I have a dynamic and dependent dropdown below. The parent dropdown fetch the active ID from database but how to auto select the child dropdown value that is stored in the same table and set it to “selected”?

Parent Dropdown (php pdo):

<?php

$keynr = new Keynr($db);
$stmt = $keynr->read();

// put them in a select drop-down
echo "<select id='key_dropdown' class='form-control' name='keyindex' required>";
    echo "<option value=''>Wähle Schlüssel...</option>";

    while ($row_content = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row_content);

         // current category of the product must be selected
        **if($position->keyindex==$id){
            echo "<option value='$id' selected>";**
        }else{
            echo "<option value='$id'>";
        }

        echo "$keynr - $content</option>";
    }
      echo "</select>"; 

?>

Child dropdown (Jquery):

<select id='repairkey_dropdown' name='keyindex2' class='form-control' required>
   <option value=''>Wähle Schadensbild ....</option>
</select>

<script>
$(document).ready(function(){
  //pageload
  $(function () {
    $("select#key_dropdown").change();
});
// detect change of dropdown
$("#key_dropdown").change(function(){

    // get id of selected team 
    var key_id=$(this).find(':selected').val();

        // set json url
        var json_url="keys_json.php?key_id=" + key_id;

        // get json data
        jQuery.getJSON(json_url, function(data){

            $("#repairkey_dropdown").html("");
            $("#repairkey_dropdown").append("<option value='0'>Wähle Schadensbild ....</option>");

            jQuery.each(data, function(key, val){
                $("#repairkey_dropdown").append("<option value='" + val.key_repairkey2 + "'>" + val.content + "</option>")
            });

        });
});
});
</script>

Child dropdown (Jquery Json):

<?php 
// set json headers
header("Access-Control-Allow-Methods: GET");
header('Content-Type: application/json');

$key_id=isset($_GET['key_id']) ? $_GET['key_id'] : die('Auftrags ID nicht gefunden.');

include_once '../config/database.php';
include_once '../objects/repairkeys2.php';

$database = new Database();
$db = $database->getConnection();

$repairkey2 = new Repairkey2($db);
$repairkey2->keyindex=$key_id;

$stmt = $repairkey2->readOneAdminDropDown();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($results);
?>

I´m not sure what is the best way to do this.

Thanks! 🙂



لینک منبع

typescript – how to append select tag option value to a web service angular 4


I have a web service to post inside it some data to create profile,

so i have a drop down list inside the form

when i try to post the data from everything on the form it works fine

but the option value from the selected option in a dropdown menu doesnt post

it gives me ‘undefined’ error

i asked the backend team and they told me it’s something in my end that i’m not binding the right data inside the json array

i need to know what is the right way to post option value

and if i selected more than one option inside the drop down, like multiselect drop down, how to post all of the options inside the array?

here is my component html:

<div class="row col-md-12" style="margin-bottom: 15px; text-align: 
center">
            <select name="country" class="rounded-inputs20 select-
select col-md-3" (change)="onChangeCountry($event.target.value)">
              <option *ngFor="let country of countries"  
[value]="country.id">{{country.name}}</option>
            </select>
            <select name="city" class="rounded-inputs20 select-select 
col-md-3"  (change)="onChangeCity($event.target.value)">
              <option *ngFor="let city of cities" [value]="city.id">
{{city.name}}</option>
            </select>
            <select name="districts"  class="rounded-inputs20 select-
select col-md-3">
              <option *ngFor="let district of districts" 
[value]="district.id">{{district.name}}</option>
            </select>
          </div>

My component ts:

name: any[];
logo: any[];
vision: any[];
mission: any[];
address: any[];
emails: any[] = [];
numbers: any[] = [];
school_id: any[];
district_id: any[];
// latitude: any[];
// longitude: any[];
numbertitle: number;
number: number;
private url = 
'https://crm.easyschools.org/api/en/schools/create/create';
 countries: any[] = []; 
 cities: any[] = []; 
 districts: any[] = []; 
imageFile: any;
schoolyears: any[] = [];
start_date: string;
end_date: string;
name_en: any[] = [];
id: number[] = [];
type: any[] = [];

private getMyBlog() {
return this._http.get('http://crm.easyschools.org/api/en/regions')
// .map((res) => res.json())
  .subscribe(countries => {
    this.countries = countries.data;
    console.log(countries);
    this.cities = this.countries.filter(x => x.id === 1)[0].cities;
    this.districts = this.cities.filter(x => x.id === 1)[0].districts;
  });
 }
 getFile(event){
 this.imageFile =  event.target.files[0];
 }
 onSubmit(form: NgForm) {
 var data = form.value;
 let formData: FormData = new FormData();
 // debugger;

 formData.append('logo', this.imageFile, this.imageFile.name);
 formData.append('name', data.name1);
 formData.append('vision', data.vision);
 formData.append('mission', data.mission);
 formData.append('address', data.address);
 formData.append('latitude', 1);
 formData.append('longitude', 1);
 formData.append('district_id', data.districts);
 formData.append('emails[0]typescript - how to append select tag option value to a web service angular 4', data.title);
 formData.append('emails[0][email]', data.email);
 formData.append('numbers[0]typescript - how to append select tag option value to a web service angular 4', data.numbertitle);
 formData.append('numbers[0][number]', data.number);
 formData.append('schoolyears[0][start_date]', data.start_date);
 formData.append('schoolyears[0][end_date]', data.end_date );
 formData.append( 'schooltypes[0][type_id]', 1 );

 this._http.post(this.url, formData)
  .subscribe(response => {
    // debugger;
    console.log(response);
  }, (err: HttpErrorResponse) => {
    console.log(err);
  });

 }

when i try the web service api on postman and give it number (1) it gives me scode 200, the issue is with the input inside the html to read the value correctly

If anything is missing or you need more details, just comment and i will give you all the data you need, i need to know what is wrong with the district_id part

feel free to try the api on postman



لینک منبع

concurrent server TCP with select in c


I have a small problem, in practice I have to let two clients communicate (which perform different functions), with my concurrent server,

I discovered that I can solve this using the select, but if I try to implement it in the code it gives me a segmentation error, could someone help me kindly?

I state that before with a single client was a fable, now unfortunately implementing the select, I spoiled a bit ‘all,

I should fix this thing, you can make a concurrent server with select ()?
can you tell me where I’m wrong with this code?

int main (int argc , char *argv[])
{
 int list_fd,conn_fd;
 int i,j;
 struct sockaddr_in serv_add,client;
 char buffer [1024];
 socklen_t len;
 time_t timeval;
 char fd_open[FD_SETSIZE];
 pid_t pid;
 int logging = 1;
 char swi;
 fd_set fset;
 int max_fd = 0;
 int waiting = 0;
 int compat = 0;

 sqlite3 *db;
 sqlite3_open("Prova.db", &db);

    start2();
    start3();

    printf("ServerREP Avviato n");

    if ( ( list_fd = socket(AF_INET, SOCK_STREAM, 0) ) < 0 ) {
        perror("socket");
        exit(1);
    }

    if (setsockopt(list_fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) < 0)
        perror("setsockopt(SO_REUSEADDR) failed");

  memset((void *)&serv_add, 0, sizeof(serv_add));   /* clear server address */
  serv_add.sin_family      = AF_INET;
  serv_add.sin_port        = htons(SERVERS_PORT2);
  serv_add.sin_addr.s_addr = inet_addr(SERVERS_IP2);


    if ( bind(list_fd, (struct sockaddr *) &serv_add, sizeof(serv_add)) < 0 ) {
       perror("bind");
        exit(1);
    }

    if ( listen(list_fd, 1024) < 0 ) {
        perror("listen");
        exit(1);
    }

    /* initialize all needed variables */
    memset(fd_open, 0, FD_SETSIZE);   /* clear array of open files */
    max_fd = list_fd;                 /* maximum now is listening socket */
    fd_open[max_fd] = 1;

    //max_fd = max(conn_fd, sockMED);
        while (1) { 
            FD_ZERO(&fset);
            FD_SET(conn_fd, &fset);
            FD_SET(sockMED, &fset);
            len = sizeof(client);

            if(select(max_fd + 1, &fset, NULL, NULL, NULL) < 0){exit(1);}

            if(FD_ISSET(conn_fd, &fset))
            { 
                if ( (conn_fd = accept(list_fd, (struct sockaddr *)&client, &len)) <0 )
                perror("accept error"); 
                exit(-1); 
            } 
         /* fork to handle connection */ 
            if ( (pid = fork()) < 0 ){      
                perror("fork error"); 
                exit(-1); 
            } 
            if (pid == 0) {                 /* child */ 
                close(list_fd);
                close(sockMED); 
                Menu_2(db,conn_fd);
                close(conn_fd); 
                exit(0); 
            } else {                        /* parent */ 
                close(conn_fd); 
        } 
        if(FD_ISSET(sockMED, &fset))
        MenuMED(db,sockMED);
        FD_CLR(conn_fd, &fset);
        FD_CLR(sockMED, &fset);
    } 

    sqlite3_close(db); 
    exit(0); 
} 



لینک منبع

perl – How to select an option in a dropdown list using WWW::Mechanized::PhantomJS


I am trying to select an option that has no value using WWW::Mechanized::PhantomJS

I have tried both methods below:

$mech->set_fields($name, $value);
$mech->field($name, $value);

This is the select element I am trying to select from:

<select class="calendarDateInput" id="enddate_Day_ID" onchange="enddate_Object.changeDay(this)">
     <option>1</option>
     <option>2</option>
     <option>3</option>
         ...
</select>

I have not been able to select any of the options. Apparently phantomjs does not have the select method. I am still a noob in perl.



لینک منبع

R Shiny select files from server-side directory


I have a folder called logs filled with different .csv files, formatted as telemetryLog-2017.21.08.54.11.csv (with varying dates and times at end).

For example, the above file could be stored like this: file <- read.csv("logs/telemetryLog-1969.2017.21.08.54.11.csv", header=TRUE)

The log files would be uploaded (in the logs folder, to shinyapps.io) along with the ui.R and server.R files. I would like to be able to obtain a list of the filenames in order to be able to select a file to display as data in a plot via selectInput (or any other way to list the files). The amount of files in the folder will not be an excessive amount; most likely it will be limited to around 50.

I have read the documentation for shinyFiles and to be completely honest I do not fully understand how the commands such as fileGetter or dirGetter work. Any help would be appreciated.



لینک منبع

Select version of Python for shell command


I’m trying to run a script to perform biterm topic modeling (BTM) (can be found here: https://github.com/xiaohuiyan/BTM). The code contains a runnable example, which can be executed via the following:

$ cd script
$ sh runExample.sh

I get an error message that reads:

=============== Index Docs =============
  File "indexDocs.py", line 18
    print(' '.join(map(str, wids)), file=wf)
                                        ^
SyntaxError: invalid syntax
=============== Topic Learning =============
runExample.sh: line 28: ../output/voca.txt: No such file or directory
g++  -c -pipe -O3 model.cpp -o model.o 
g++  -c -pipe -O3 infer.cpp -o infer.o 
g++  -c -pipe -O3 main.cpp -o main.o 
g++ model.o infer.o main.o -o btm
../src/btm est 20  2.500 0.005 5 501 ../output/doc_wids.txt ../output/model/
runExample.sh: line 31: 51872 Segmentation fault: 11  ../src/btm est $K $W $alpha $beta $niter $save_step $dwid_pt $model_dir
================ Infer P(z|d)===============
../src/btm inf sum_b 20 ../output/doc_wids.txt ../output/model/
Run inference:K=20, type sum_b ====
load p(z):../output/model/k20.pz
[Error] file not find:../output/model/k20.pz
================ Topic Display =============
Traceback (most recent call last):

I’m guessing that this is simply me using the wrong version of Python. If so, how do I change the version of Python that I am using? Or if this is an actual recognizable error in the code how do I correct it?



لینک منبع

select maximum value for each returned record in mysql


My tables look something like this
table 1 :
relid BID
۱ ۱
۱ ۲
۱ ۳

table 2:
id BID priority info
۱ ۱ ۰ Json string
۲ ۱ ۱ **
۳ ۱ ۲ ****
۴ ۲ ۰ ***
۵ ۲ ۱ ****
۶ ۳ ۰ ****

the question is that I want to select all the BID’s with only the highest priority from table2 using inner join with table1, which means I want to get this result

id BID Priority info
۳ ۱ ۲ Json String info
۵ ۲ ۱ *
۶ ۳ ۰ *

I’ve used this query and it works fine but with large numbers of records it works too slow !! the fetching time may last up to 70 seconds in MySQL which is a disaster for my server !!!

select * from table1 inner join table2 on table1.BID = table2.BID where table1.id = 1 and table2.priority = (select max(priority) as m from table2 where table1.BID = table2.BID)

anyone has other suggestions that might work with better performance!



لینک منبع

select – Laravel eloquent selectRaw for SQL injection


I have query:

$typeCancel = 'cancel'; $typeRefund = 'refund';
$query = Order::select(DB:raw('order.*,'
    "IF (order.type IN (?, ?), (order.amount * -1), order.amount) AS custom_amount"))
->where('provider', 1)
->setBindings([$typeCancel, $typeRefund], 'select')
->get();

And it work.
How can I do something:

... IF (order.type IN (?) ...
... ->setBindings([$types], 'select')

I try this:

$types = "'{$typeCancel}','{$typeRefund}'";
... IF (order.type IN (?) ...
... ->setBindings([$types], 'select')

But it not correct, result query see like that:

... IF (order.type IN ("'cancel','refund'") ...



لینک منبع

select – mysql if exist update and delete not exist insert new rows and delete


this is mysql table named producttab

http://sqlfiddle.com/#!9/0b2417/1

it has 6 columns
id, code, order, newLocation, oldLocation, quantity

I want
SELECT * from producttab WHERE NewLocation = PROD

IF EXIST (OldLocation = 00001) in NewLocation UPDATE sum quantity (quantity OldLocation + quantity NewLocation) in NewLocation = 00001
AND DELETE ROW when NewLocation = PROD AND OldLocation = 00001

IF NOT EXIST (OldLocation = 00001) in NewLocation
INSERT New row WHEN values fields SELECTED
AND DELETE AND DELETE ROW when NewLocation = PROD AND OldLocation = 00001
And the same with the rest of the fields



لینک منبع

php – SQL – Select ALL rows that are LIKE%…% of each other (All Similar Rows)


For example, lets say in Column source I have the following entries

SourceFileEmbed122
SourceFile1333
SourceItem13366
PreLoadSource7755

And I do a query of SourceFile it should match row 1 and 2 and show me all the column data for that row, but if I search for example: PreLoadSource or SourceItem it shouldnt show anything, as there is only 1 row that has a similar entry.

Kinda like a if contains sort of thing



لینک منبع