Note that there are some explanatory texts on larger screens.

plurals
  1. POJoomla: How to use update multiple rows at once in a component within MVC framework?
    primarykey
    data
    text
    <p>Just starting out with PHP and Joomla development, have one big obstacle that I can't wrap my head around. </p> <p>Building an assessment tool on the backend. I have one table ("questions") that contain a bunch of questions that are grouped by sections (1-9). I have another table ("students") that will be populated by taking all registered users, displaying one user and section along with the questions. Then the teacher will check off that they've completed those questions.</p> <p><strong>Questions Table:</strong></p> <pre><code>questionID sectionID question 1 1 Blah Blah 1 2 1 Blah blah 2 3 2 Bork bork 4 3 Bork de bork </code></pre> <p><strong>Students Table:</strong></p> <pre><code>id userID questionID passed 1 85 1 1 2 85 2 3 85 3 4 85 4 1 5 85 5 1 6 92 1 1 7 92 2 1 8 92 3 9 92 4 10 92 5 1 </code></pre> <p>Planning on using <code>INSERT…ON DUPLICATE KEY UPDATE</code> so if the values don't exist in the "students" table then it will just update each row, and if the values do exist then they'll be updated (along with a timestamp and a few other fields). </p> <p>I'm pretty sure I can build the query (suggestions welcomed! ) but right now I have no idea how to use Joomla's MVC framework to make this happen. It looks like jTable isn't good for returning multiple rows which means using JModelList....but then how to use Joomla's functionality to make a Save button (JToolbar?) that will update or insert depending on if that row exists? Feel like I have all the pieces but don't know how they go together. The students view is very simple, one controller/model/view.html.php/tmpl-default.php.</p> <p><strong>References:</strong></p> <pre><code>http://www.sourcecodester.com/php/3863/updating-multiple-rows-mysql-using-php.html http://forum.joomla.org/viewtopic.php?p=2263231 http://forum.joomla.org/viewtopic.php?p=2406831 http://forum.joomla.org/viewtopic.php?p=1745675 http://forum.joomla.org/viewtopic.php?p=1675454 (promising but dated) http://forum.joomla.org/viewtopic.php?p=2506722 http://stackoverflow.com/questions/1305863/update-multiple-rows http://docs.joomla.org/JModelList/1.6 http://docs.joomla.org/JModelList::getListQuery/1.6 http://docs.joomla.org/Using_the_JTable_class http://docs.joomla.org/How_to_use_the_JTable_class http://docs.joomla.org/JTable http://docs.joomla.org/JTable/getobjectslist (promising...maybe?) </code></pre> <p><strong>Questions:</strong></p> <ul> <li><p>How to use Joomla's MVC framework to make a multirow update...for dummies.</p></li> <li><p>Where does everything go? </p></li> <li><p>If there's a different way of doing this I'm totally open to suggestions.</p></li> </ul> <p>Thanks!</p> <p><strong>EDIT</strong></p> <p>Realize this is probably too broad. Here's a bit more:</p> <ul> <li><p>I've gone through the Joomla MVC guide ("here's some code - PLOP") and Lynda (better but also in the "here's some code - PLOP" category).</p></li> <li><p>I've set up a few simple table views/updates using those guides. These involved making one view that returned all the values and another that would pull up one record (either to edit or new), modifying the XML file to account for the different data input types, etc.</p></li> </ul> <p>My confusion in a nutshell is this. Using those guides it seems that the edit view using JTable is meant to display ONE record. To display more than one record you use JModelList. So what do you use to display multiple records and update them? Or do you just ignore what they're supposed to do and just throw a looping update in there? Trying to learn and do this the correct way which has been a bit harder to understand than anticipated.</p> <p>Again, thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload