The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Query results - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: Query results (/showthread.php?tid=848) |
Query results - MHALL1 - 11-23-2017 Hi, Just a quick query about retrieving data from the DB. Normally I would use results() to get the data I want to display. But take the scenario where I want a specific value and do: $somethingQ = $db->query("SELECT * FROM db WHERE category = 'this'"); $somethingR = $somethingQ->results(); If I try: $somethingR->id, it doesn't give me the data, but if I use first() above it does. Just wondering how I would structure something to have multiple input text boxes, that return with a value stored in the DB but if changed/updated would be updated to their new value; each item's input would be item[]. Hope that makes sense. Query results - mudmin - 11-23-2017 It absolutely makes sense. That's the big benefit of first. You basically have three different ways to do what you're talking about. The first is to use the OCE (one click edit feature). You can see it in action in the "IOT and MQTT" button on your dashboard. If you edit that MQTT server on the right, you get an idea for the look and feel. Basically click on a box lets you edit it and clicking off the box changes it in the database without reloading the page. The users/mqtt_settings.php file is fully commented to show you how to implement this. The second is to use a foreach loop. I decided to write you a code snippet that you can paste right in the body of your index.php file to test how this works. Essentially you need your name attribute on the form to also have the id of the row you want to update in it. And instead of name just being a name, you need it to be an array. It's kind of hard to explain so I just wrote one that will let you edit the first name of every user in your database. Note that you may want to add some more checks before you allow it to update the database, but this is more of an example of how it works. https://pastebin.com/Tn5PwdZA I hope that helps. It's a weird concept, but I think this example is straightforward enough to help. Query results - MHALL1 - 11-23-2017 Thank you mudmin, I appreciate you taking the time to help & your examples are very useful. I'll have a read, thanks again. |