Forum Replies Created

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter NicolasMous

    (@nicolasmous)

    Dear pierjeant,

    I’ve got my problem solved, though, I must note that it is pure html and PHP implemented in WordPress (so without all the WordPress styled PHP) and this might be bad practice. Nonetheless, it works!

    So up in front I must know the following:
    -You have access to the backend (you can reach your participant database files and your database – which is probably phpmyadmin or something)

    To see an example of my checkbox search database, go to the following site: portal.e-ucare.eu. There you can click on the Database tab.

    P.s. I am in an different timezone since I am from the Netherlands so replies might be a few hours later;)

    Regards,

    Nicolas

    Thread Starter NicolasMous

    (@nicolasmous)

    alright, actually by looking at my linked image i suddenly thought about the link that is displayed in the uploaded files page. I checked it just to be sure that the image was in the right (upload) folder. And so it wasn’t, for some reason my old pictures were all uploaded in sub folder 08 while the images i upload now are stored (at least, the link says it) in sub folder 10, but they aren’t stored there (the folder is empty).

    So the question now is, why are they being uploaded in the folder 10 and not anymore to 8 and why doesn’t it store the files there?

    I fixed the problem now with a workaround by copying the image in the 10 folder.

    Thread Starter NicolasMous

    (@nicolasmous)

    For some reason, when i was about to create more images for you, it is ALL working again… It is really strange but i think it caused because something was open before and is closed now?? I have absolutely no idea what caused the errors but it is working again…

    Thread Starter NicolasMous

    (@nicolasmous)

    Alright, it was indeed quite simple but i just didn’t knew immediately which direction to go. I added a simple href and selected the right comlumn by adding a AS to the query. Thank you anyway!

    Thread Starter NicolasMous

    (@nicolasmous)

    xnau, thank you for your reply! But i think i need a little more information then that since i am a bit stuck. The link where the uploaded files are stored is clear (i found them). Though, i need some (easy way) to attach those links to the right database field names. Like, i have no clue how to attach the proper url to the field it belongs to. So the question is, what selects that proper field>?

    Thread Starter NicolasMous

    (@nicolasmous)

    Hmm ok, fair enough. But im trying to retrieve serialized data in the database (array values) based on the checkboxes that a user selects (the checkboxes values are the same of the stored arrays). I try’d to unserialize the values of the database but i find this quite hard to do especially with multiple serialized values which are being stored in a single variable.

    But i found a better solution with the use of a simple REGEXP in my query which kinda does the same as the unserialize.

    But thanks anyway!

    Thread Starter NicolasMous

    (@nicolasmous)

    Dear xnau,

    As promised i would reply if i had found / created some kind of solution. While here it is (perhaps you could give some advice in what to do better on it tho).

    Ill go over the code step by step:

    1. I firstly created a new template based on the pdb-search (could be anything though since all the code inside it was cleared anyway).
    2. I cleared all the code in this template and started created my own code (can still call the template though with a shortcode, in this example: [pdb_search template=new].)
    3. I then started to create the form with the checkboxes, for testing purposes i created 3 checkboxes with a submit button for the searching. The code:

    <form method="post">
    <input type="checkbox" name="columns[]" value="1" /><label for="Authors">Authors</label><br />
    <input type="checkbox" name="columns[]" value="2" /><label for="Research Source">Research Source</label><br />
    <input type="checkbox" name="columns[]" value="3" /><label for="Research Title">Research Title</label><br />
    <input type="submit" name="go" value="Submit"/>
    </form>

    4. Next i have set the column names with a respond to the submitted checkboxes. When no checkboxes are selected, or just at loading the page, i made sure that all the database information of the 3 columns is shown.
    The code:

    <?php
    $all = false;
    $column_names = array('1' => 'Authorss', '2' => 'Research_Source', '3' => 'Research_Title');
    if(isset($_POST['columns'])){
        $column_entries = $_POST['columns'];
        $sql_columns = array();
        foreach($column_entries as $i) {
            if(array_key_exists($i, $column_names)) {
                $sql_columns[] = $column_names[$i];
            }
        }
    } else {
        $all = true;
        $sql_columns[] = "authorss";
        $sql_columns[] = "research_source";
        $sql_columns[] = "research_title";
    
    }

    5. Next thing i did was making the connection to the WordPress database and the participant database table. This was however a bit different then usual php database querying and connection because of working in WordPress. The code:

    global $wpdb;
    
    $tmp = $wpdb->get_results( "SELECT ".implode(",", $sql_columns)." FROM wp_participants_database");
    ?>

    6. To complete the code i output the selected database information (based on the checkbox selection) and wrapped it in table cells. The code:

    <style type="text/css">
      table{
        border-collapse: collapse;
        border: 1px solid black;
      }
      table td{
        border: 1px solid black;
      }
      table th{
        border: 1px solid black;
      }
    </style>
    
    <?php
    echo "<table>
        <tr>";
    
    foreach($column_names as $k => $v) {
        if($all || (is_array($column_entries) && in_array($k, $column_entries)))
            echo "<th>$v</th>";
    }
    echo "</tr>";
    
    if(count($tmp)>0){
        for($i=0;$i<count($tmp);$i++){
            echo "<tr>";
                foreach($tmp[$i] as $key=>$value){
                    echo "<td>" . $value . "</td>";
                }
                foreach($column_names as $k => $v) {
                    if($all || (is_array($column_entries) && in_array($k, $column_entries))) {
                        echo "<th>".$row[$v]."</th>";
                    }
                }
            echo "</tr>";
        }
    }
    
    echo '</table>';
    ?>

    xnau, if you have any other suggestions to this code then i would be glad to hear it:) I hope this step by step explanation can also help others! *Small note: many thanks to Zeusarm on stackoverflow who helped me out with this code!

    Thread Starter NicolasMous

    (@nicolasmous)

    Ah to bad! Thank you anyway xnau! Like you suggested, I am now busy to create my own (checkbox) form with an query to get the data. Once i have got it working, or when i have some related database questions of the participant database (like result formatting/putting it in the tables or something like that) i will come back to you on it in this post (if you don’t mind)!

    By the way, could you give a rough estimate of when you think that plugin your working on is done? Is it around 1-3 months, 3-6 or a year or so?

    Once again, thank you for the help!

    Thread Starter NicolasMous

    (@nicolasmous)

    Thank you for your reply! But once again im getting a bit stuck.

    So the part of removing dropdown selector goes perfectly.

    I removed the $this->column_selector(false, true, false, 'column'); and replaced it with <input type="hidden" id="search_field_select" name="search_field[]" class="search-item" value="none">

    I set the value to none because i just don’t want to use the selector, the checkboxes should do the selecting for the end user.

    Secondly i also removed the <?php $this->search_form() ?> and replaced it with the plain html:

    <input class="search-item" type="hidden" value="LIKE" name="operator">
    <input id="participant_search_term" class="search-item" type="checkbox" value="" name="Name">Option 1<br>
    <input type="submit" value="Search" name="submit_button">
    <input type="submit" value="Clear" name="submit_button">

    For better understanding purpose: I have (for testing) 4 database fields (don’t mind their names, its just for testing) with some data in it:
    1. Name
    2. Lastname
    3. City
    4. Country

    So i went to test this piece of code but it doesn’t seem to work yet.
    I first try’d to filter the options just with one checkbox (for testing). Though, when i check the checkbox it returns to me: Please type in something to search for.

    So, i messed around a bit and changed the name back to value and also try’d a couple things in the value=. Though nothing seemed to work.
    The next thing i did was setting the selector value (which i had set to none) to a database field: so i changed the value from ‘none’ to ‘name’. In the checkbox / search html i set the value to ‘Barry’ (a name i stored earlier in the database field name) and the name back to ‘value’. Suddenly i had a filter (results) for the database field Name!

    Now, while that worked i try’d to add filters for the other stored names as well in the Name database field. So i try’d to add the same checkbox input but now with an different value, namely the second stored name. This sadly didn’t work and both the options only returned the last given name value.
    Besides that i also try’d to create a filter for not only the database field ‘Name’ but also for the others (lastname, city, country). I did this by adding more hidden inputs but with the values of the other database fields. Though this also dint work.

    So the question is:
    1. How to add multiple filter options (database fields)
    2. How to have the checkbox search for the multiple values in those database fields. (Think this requires 2 ‘search forms’ with the right checkboxes where search form 1 has checkboxes with values that look in database field 1 (Name for example) while searchform 2 has checkboxes with values that look in database field 2 (Lastname for example).

    I am truly sorry that you need to over-explain this to me and i hope you are not giving up on me just yet;) Just a small note: It is a bit harder for me to understand the explanation immediately as English is not my native language (as you probably noticed). \

    Thanks in advance!

    Thread Starter NicolasMous

    (@nicolasmous)

    xnau,

    It works like a charm! Many thanks.

    As i see a lot of people in posts looking for the same i’ll post the code with a step-based to-do’s in here for this functionality.

    So this is for creating multibox fields and attach links to the options:

    1. create a custom template based on pdb-list
    2. insert the function code on top of the page:

    function value_link($value) {
      $map = array(
        'Yes' => 'https://www.google.nl',
        'No' => 'https://www.hotmail.com'
        'Something else' => 'https://www.something.com'
      );
      return $map[$value];
    }

    3. insert the following code between the tbody:

    <?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?>
        <?php $record = new PDb_Template($this); ?>
      <tr>
        <?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
          <td class="<?php echo $this->field->name ?>-field">
            <?php
    
    if ($this->field->name === 'edit_link') {
      $output = '';
    
      foreach ($this->field->value as $the_value) {
    
        $the_value = trim($the_value); // in case there are spaces
        $output .= '<a href="' . value_link($the_value) . '">' . $the_value . '</a> ';
      }
      echo $output;
    } else {
      $this->field->print_value();
    }
    ?>
          </td>
      <?php endwhile; // each field ?>
      </tr>
    <?php endwhile; // each record ?>

    4. Change the fields to your fields (so field is called here edit_link but this should be named to your own created multibox field.

    Anyway, thanks a lot xnau!

    Thread Starter NicolasMous

    (@nicolasmous)

    Dear xnau,

    So i went and started off with enabling/creating check box searching. Though, the problem is that i have absolutely no clue how to do it, but i guess it involves this line of code: $this->column_selector(false, true, false, 'column');. I made a custom template based on the search-default.

    Could you give some pointers to help this absolutely nitwit person-> being me;) By the way, i also donated some money for your tremendous help and support, did you receive it?

    Thanks in advance!

    Nicolas

    Thread Starter NicolasMous

    (@nicolasmous)

    Dear xnau,

    Thank you for your fast replies and your answer!

    So I’ll give you an status update. I try’d to go from the point of your piece of code. I had several error messages which I ficed. With the fixes in place the code now looks like:

    <?php
    if(!function_exists("value_link")) {     //First error message was here that the function already existed so I included the !function_exists
    function value_link($value) {
      $map = array(
        'Yes' => 'https://www.google.com',
        'No' => 'https://www.hotmail.com'
      );
      return $map[$value];
    }
    }
    
    if ($this->field->name === 'edit_link') {
      $output = '';
      $value_array = explode(',', (string) $this->field->value); //Second error here, had to insert the string because object to string wasn't possible)
      foreach ((array)$value_array as $the_value) {
        $the_value = trim($the_value); // in case there are spaces
        $output .= '<a href="' . value_link($the_value) . '">' . $the_value . '</a> ';
      }
      echo $output;
    } else {
      $this->field->print_value();
    }
    ?>

    So when I ran this piece of code, the links still wouldn’t work.. IN all the examples (one multiselect stored as well as both stored) gives still the word: Array in return. This Array word does have a link though, but when I click this link it returns me to the page I was on already. Besides that, for the stored example of two multiselect options, it still return only ONE Array word (instead of two).

    Thanks in advance!

    Thread Starter NicolasMous

    (@nicolasmous)

    Thanks for your reply!

    Though, I am getting stuck as all the things I tried aren’t working.

    I am working with this piece of code:

    <?php $record = new PDb_Template($this); ?>
      <tr>
        <?php while( $this->have_fields() ) : $this->the_field(); // each field is one cell ?>
          <td class="<?php echo $this->field->name ?>-field">
            <?php
            /*
             * put the edit link URL into the link property of the field
             */
            if ($this->field->name == 'edit_link') {
              $this->field->link = $record->get_edit_link(https://testing-purposes.com/);
            }
            $this->field->print_value();
            ?>
          </td>

    I tried to work with the ‘values’, use the && to select it, etc. But still it all doesn’t work, probably because I am way off (lacking the know how). Could you point me a bit in the right direction? For example: how do I target the values in the field? Or how do I assign the link to that values? Just need a bit coding direction. (BTw I kept using edit_link for testing purposes).

    Thank you in advance!

    Thread Starter NicolasMous

    (@nicolasmous)

    *Update:

    So I found the ‘Adding an Edit Record Link to the Frontend List’ and thought perhaps it would also be possible with this.

    So I followed the tutorial and created the link, though this tutorial (and code) doesn’t seem to work on multiselect boxes and their values.. And though, if it worked it still needed some kind of if statement to look which of the multiselect options was chosen (if option 1 was chosen –> then insert a link to website/page A and if option 2 was chosen –> then insert a link to website/page B

    Thread Starter NicolasMous

    (@nicolasmous)

    *ignore above post as it wasn’t supposed to go in here!

Viewing 15 replies - 1 through 15 (of 20 total)