Troubleshooting my SQL query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Troubleshooting my SQL query (/showthread.php?tid=26733) Pages:
1
2
|
Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]jonyork[/eluser] Alright, if I run an sql query in phpmyadmin looking like this I get my desired value Code: SELECT `company` FROM `user` WHERE `username` = 'jonathan' However, ive been hitting my head on the table. this is my CI code Code: $this->db->select('company'); and this is the subsequent print_r output Code: CI_DB_mysql_result Object ( [conn_id] => Resource id #28 [result_id] => Resource id #33 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 1 [row_data] => ) help is greatly appreciated Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]JHackamack[/eluser] try Code: print_r($company->result()); Code: print_r($company->row()); for just the first row of the returned result. Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]ascotan[/eluser] As noted above you don't want to print the entire CI_DB_mysql_result object structure. Use the Active Record methods to get your results like "row" and "results" Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]bretticus[/eluser] $this->db->last_query(); Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]jonyork[/eluser] Quote: $this->db->last_query(); Code: $company = $this->db->last_query(); returns with SELECT `company` FROM (`user`) WHERE `username` = 'jonathan' Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]jonyork[/eluser] Quote: $this->db->last_query(); Code: $company = $this->db->last_query(); returns with SELECT `company` FROM (`user`) WHERE `username` = 'jonathan' Quote: print_r($company->row()); returns with stdClass Object ( [company] => ValueDesired ) Forgive me for being new at CI, but where/what do I do to get it as string variable $company? Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]JHackamack[/eluser] Code: $company = $this->db->get('user'); Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]jonyork[/eluser] [quote author="JHackamack" date="1264151862"] Code: $company = $this->db->get('user'); when I use this, i get the following Quote:A PHP Error was encountered were getting closer (does everyone run into these snags at first or is it just me?) Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]JHackamack[/eluser] It took me a bit to get the active record class but I've managed to get it down pat, at least I thought. Try this: Code: $this->db->select('company'); Troubleshooting my SQL query - El Forum - 01-21-2010 [eluser]jonyork[/eluser] Awesome! Thank you for all your help. Might have a few more questions in the next few days, but so far, im really liking CI. Theres a learning curve for sure, but it does seem to help out in the long run. heres the final code Code: <?php |