• Resolved winnischneider

    (@winnischneider)


    I extract from a dropdown Job names and save the job code in the database, after this I match wth other job codes to get a matched list . All this is function now, but now I need to load into the tabel as well over a join the Job name, but it get loaded the code only. I created a nother field (berufsguppe) which I want to fill with a join based on the code but it will not work. I tried also with the methode "write_participant()" but as well without success. Have somebody any idea how I can get this to work?
    THanks very much for responds...
    Winni
    
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Hi Winni,

    I think it will be easier to answer your question if you explain what you are trying to achieve, there may be an easier way than what you are trying.

    Thread Starter winnischneider

    (@winnischneider)

    Hi thanks for interest first. I try to explain in a nother way. I have participants in the participant table which can select from the table occupations some occupations (each occupation has a uniqu code) I store in the participants table the code. A nother user can choose as well from the occupation table the occupation-group and get matched via the occupation code with the frist users. this is all function so far, also the matched results are displayed correctly with the help of a join, to get instead of the code the occupations string displayed. (The join with the code is also needed because the table is multilinguals but the displying I need only in one language.) Now the problem is in displaying the general table with all results, where the occucpation field has just the code only but I need the string from the occupation table. Therefor I tried several things but discovered, the it seams do be unpossible to write something in the database and get this displayed. Finally it was posssible to record the labels in the database but they did not want to get displayed. Last idea was to create a field occupation_label in the participant database to get as well a field in the db table from the participants and to fill up this with a Join request and yes it got filled up but the data did not got displyed. My Question is: is there a kind of security check which does not permit db chances which get not made over the registration or update function? And is there a possibllity for a work around?

    I hope you understand something of what is mmy problem and appreciate any hint.

    Thread Starter winnischneider

    (@winnischneider)

    Sorry I was study your hooks a bit better and could resolve the problem with this code snipet:

    // Hook into the after_submit_signup and after_submit_update hooks
    add_action('pdb-after_submit_signup', 'update_occupation_label_field');
    add_action('pdb-after_submit_update', 'update_occupation_label_field');
    
    function update_occupation_label_field() {
        // Check if the necessary form fields are present in the $_POST data
        if (!empty($_POST['beruf']) && !empty($_POST['id'])) {
            global $wpdb;
            
            // Get the participant ID and occupation code from the $_POST data
            $participant_id = $_POST['id'];
            $beruf_code = $_POST['beruf'];
            
            // Query to fetch the occupation label from the database
            $query = $wpdb->prepare("
                SELECT o.berufe AS berufsgruppe
                FROM {$wpdb->prefix}occupation AS o
                WHERE o.code = %s
            ", $beruf_code);
            
            $occupation_label = $wpdb->get_var($query);
    
            // Update the participant's 'berufsgruppe' field
            if ($occupation_label !== null) {
                Participants_Db::write_participant(array('berufsgruppe' => $occupation_label), $participant_id);
            }
        }
    }
    

    So thanks very much for your time and attention.

    Regards Winni

    Plugin Author xnau webdesign

    (@xnau)

    Thanks for sharing how you solved it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Recording a field over Join’ is closed to new replies.