The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Help to query the database - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30) +--- Thread: Help to query the database (/showthread.php?tid=276) |
Help to query the database - GePraxa - 09-21-2016 I'm looking at the manual, but I think not all understand as it is, for example, we find the following documentation: $director_id = 1; $query = $db->query("SELECT * FROM camps WHERE director_id = ?", array($director_id)); $x = $query->results(); Then, as I do to show results, ie in this case I want a list of "names" in "camps" ... I just want to know how to do the "echo" or as I show in html the results? I propose to make a manual like this. Is costing me a lot of work interact with the database and predefined classes, I really do not know how I am suffering. Most rookies just want to show something that is already in the database, send the information to achieve, but I can not show it. I do not want to use functions because it is more difficult for me, I just want a simple query and display the results. Could you help me? Help to query the database - mudmin - 09-22-2016 We are creating a wiki to better document using userspice. That said, one thing to note...there is no obligation to use our database class. If you add your own (as long as you don't call it DB), it will work just fine (even if it is on the same page) with ours. That said. In the example above... Code: $query = $db->query(“SELECT * FROM camps WHERE director_id = ?”, array($director_id)); So....what do you do with that query? You have options. That entire query is now called $query. You can get ALL the information back by Code: $x = $query->results(); Or just the first response if you do Code: $x = $query->first(); I think what you're asking though is how do you get the info inside back. It's super easy. It is a good idea to test your results by doing dump($x); //gives you the full list of everything you got back. Then if you have a column named 'name', just do $x->name; To echo it you would do something like this. Welcome to our website, <?=$x->name?>. It's great to have you. Help to query the database - GePraxa - 09-22-2016 Thank you very much for the reply and the great help ... I said he was very interested in integrating "MeekroDB" in the project but to try out errors everywhere since the classe is called "DB" attempt to change the classes by another name but still I did not work, I would love to integrate but could not, it was a great frustration because it would have been helpful. By chance you know this class and if so, have an idea of how to integrate it without affecting the operation of "userspice"? Or how it could change by a replacement of "DB" by another word or something? Help to query the database - mudmin - 09-24-2016 It's easy to include that class. Download Meekro 2.3 Copy it to the classes folder. Edit line 20 in the meekro class and replace class DB{ with class DB2{ Put in your database credentials on lines 22-25. Find/replace with in the rest of the class... Find: DB:: Replace: DB2:: Edit users/init.php around line 56 to add your require_once $abs_us_root.$us_url_root.'users/classes/meekrodb.2.3.class.php'; You're good to go. Everything should work fine and you can use your meekro class for your stuff and let our db class do its thing. Help to query the database - GePraxa - 09-25-2016 This really worked, THANK YOU! Lanzo some mistakes but is solved with the following: If someone else wants to do this, you must change into "meekrodb.2.3.class.php" line 161 the following: $db_class_vars = get_class_vars('DB'); -> $db_class_vars = get_class_vars('DB2'); |