The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query results
#1
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.

  Reply
#2
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.
  Reply
#3
Thank you mudmin, I appreciate you taking the time to help & your examples are very useful.
I'll have a read, thanks again.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)