• Good afternoon,

    While working on a project I came across a problem I’m not able to find the solution myself. I’ve made a dropdown list with names of people and a table under it where some data about that name will be displayed. The goal is to select a name from the dropdown and the tables than shows the corresponding data for that name…

    How to update the content of the table, so the right data is shown?

    Is this the best aproach, or is it easier to redirect to a new page where the table is shown (sending the selected name along e.g.)?

    What i made so far: The list is filled with the available names and the table is filled with some data from a known name: ‘jessebeekman’.

    <?php
    
    global $wpdb;
    /* wpdb class should not be called directly.global $wpdb variable is an instantiation of the class already set up to talk to the WordPress database */ 
    
    $mydb = new wpdb('root','','vitamin_data','localhost');
    
    $result = $mydb->get_results( "SHOW TABLES FROM vitamin_data "); 
    
    //echo "<pre>"; print_r($result); echo "</pre>";
    /* If you require you may print and view the contents of $result object */
    
    echo "<strong>Naam</strong>"."  "."<br>";
    
    ?>
    <select name="gebruikers">
    <option value="naam"> </option>
    <?php foreach($result as $row){ ?>
     <option value="naam">  <?php echo $row->Tables_in_vitamin_data ?>  </option>
     <?php } ?>
    </select>
    
    <table id="myTable" class="tablesorter">
    <thead>
    <tr>
        <th>Naam</th>
        <th>Herhalingen</th>
        <th>Versie</th>
        <th>Gedaan</th>
        <th>Datum</th>
    </tr>
    </thead>
    <tbody>
    
    <?php $result = $mydb->get_results( "SELECT * FROM jessebeekman"); ?>
    <?php foreach($result as $row) { ?> 
    
    <tr>
        <td> <?php echo $row->Naam ?> </td>
        <td> <?php echo $row->Herhalingen ?> </td>
        <td> <?php echo $row->Versie ?> </td>
        <td> <?php echo $row->Gedaan ?> </td>
        <td> <?php echo $row->Datum ?> </td>
    </tr>
    
    <?php } ?>
    
    </tbody>
    </table>

The topic ‘Updating table content’ is closed to new replies.