1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Need some guidance, I want to save multiples values from a html table into a mysql database

Discussion in 'Community' started by AlexTCGPro, Jun 26, 2020.

  1. AlexTCGPro

    AlexTCGPro Member

    Level: Community
    Hey guys.
    I have this table 'students', with multiple fields.
    I made an article with php code and created a simple html table with some of those values, that generates a row every time a condition is meet, plus two new fields I want to be stored, a button an a textarea.

    So, my code is like this:

    Code (Text):
    <?php
    $list = '1,2,3,4,5,6'
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select(array('id', 'name', 'lastname', 'picture'))->from('students')->where('id IN (' . $list . ') ')->order('lastname ASC');
    $db->setQuery($query);
    $studs = $db->loadObjectList();
    $linecountStu++;
    echo '<table>';
    foreach ($studs as $stud) {
    echo '<tr id="' . $stud->id . '">';
    echo '<td>#' . $linecountStu++ . '</td>';
    echo '<td>' . $stud->name . ' ' . $stud->lastname . '</td>';
    echo '<td><img src="' . $stud->picture . '"/></td>';
    echo '<td><textarea name="text" rows="3" placeholder="Comment..." maxlength="500" style="resize: none;"></textarea></td>';
    echo '<td><button onclick="button(this)" value="0"></button></td>';
    echo '</tr>';
    }
    echo '</table>';
    ?>
    I was thinking on just making a button that immediately inserts those values to a database, student id, name and lastname, textarea and the value of the button (which changes once clicked), but I can't seem to get any of those values with php. Can you give me a hand?

    Basically, for each table row insert the values of its <td>.
     
    Last edited: Jun 26, 2020

Share This Page