Undefined valuable |
Hello guys,
I've two models mark_m and setting_m and am try to get some data from setting table and display it in mark view but when i try i get this kind of error Quote:A PHP Error was encountered Below is my code; setting_m.php -- model PHP Code: public function get_school() { mark.php -- controller PHP Code: function __construct() { view.php -- views Code: <section class="panel"><?=$schoolTitle->sname?></h1> where am i going wrong please help me
in get_school method you are returning object of row objects, you need to fetch only one row.
update your method: PHP Code: public function get_school() { use print_r or var_dump functions for debugging your code (05-09-2017, 08:13 AM)php_rocs Wrote: @kayinja.denis As I know, You dont have to be sure, if it 1 or more rows retrieved, to use row() function, it retrieves first row. You right, better it is better to write sql code and test it in db, and then apply in php code
@neuron
when i use your code PHP Code: public function get_school() { PHP Code: <?=var_dump($schoolTitle)?> but when i change $query = $this->db->query("SELECT sname FROM setting"); to $query = $this->db->query("SELECT * FROM setting"); and dump again, I get all the results so when i try to retrieve <h1><?php echo $schoolTitle->sname?></h1> i get the following error... Quote:A PHP Error was encountered thanks
Show a dump of the object or array that is returned from your query.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-10-2017, 03:48 AM)InsiteFX Wrote: Show a dump of the object or array that is returned from your query. Quote:array(25) { [0]=> array(2) { ["fieldoption"]=> string(7) "address" ["value"]=> string(22) "p.o box 2 njeru uganda" } [1]=> array(2) { ["fieldoption"]=> string(10) "attendance" ["value"]=> string(3) "day" } [2]=> array(2) { ["fieldoption"]=> string(10) "automation" ["value"]=> string(1) "5" } [3]=> array(2) { ["fieldoption"]=> string(21) "auto_invoice_generate" ["value"]=> string(1) "0" } [4]=> array(2) { ["fieldoption"]=> string(13) "backend_theme" ["value"]=> string(5) "basic" } [5]=> array(2) { ["fieldoption"]=> string(13) "currency_code" ["value"]=> string(3) "UGX" } [6]=> array(2) { ["fieldoption"]=> string(15) "currency_symbol" ["value"]=> string(2) "/=" } [7]=> array(2) { ["fieldoption"]=> string(5) "email" ["value"]=> string(30) "[email protected]" } [8]=> array(2) { ["fieldoption"]=> string(16) "fontendorbackend" ["value"]=> string(1) "1" } [9]=> array(2) { ["fieldoption"]=> string(13) "fontend_theme" ["value"]=> string(5) "basic" } [10]=> array(2) { ["fieldoption"]=> string(13) "fontorbackend" ["value"]=> string(1) "0" } [11]=> array(2) { ["fieldoption"]=> string(6) "footer" ["value"]=> string(28) "Copyright ©florasjunior" } [12]=> array(2) { ["fieldoption"]=> string(16) "google_analytics" ["value"]=> string(0) "" } [13]=> array(2) { ["fieldoption"]=> string(8) "language" ["value"]=> string(7) "english" } [14]=> array(2) { ["fieldoption"]=> string(6) "mark_1" ["value"]=> string(1) "1" } [15]=> array(2) { ["fieldoption"]=> string(6) "mark_3" ["value"]=> string(1) "0" } [16]=> array(2) { ["fieldoption"]=> string(4) "note" ["value"]=> string(1) "1" } [17]=> array(2) { ["fieldoption"]=> string(5) "phone" ["value"]=> string(13) "+256789960188" } [18]=> array(2) { ["fieldoption"]=> string(5) "photo" ["value"]=> string(132) "a8240c1de32628b9ad6a2fae89c2eb4013da24573fd810e49248eae383bf15442178739622ae9f9f9ab93c3f329f6e284cb239942fc9225b24b6c1c1978700c5.png" } [19]=> array(2) { ["fieldoption"]=> string(13) "purchase_code" ["value"]=> string(36) "f541d688-9d40-40db-99fb-65e6f80692ab" } [20]=> array(2) { ["fieldoption"]=> string(11) "school_type" ["value"]=> string(9) "classbase" } [21]=> array(2) { ["fieldoption"]=> string(11) "school_year" ["value"]=> string(1) "1" } [22]=> array(2) { ["fieldoption"]=> string(5) "sname" ["value"]=> string(12) "florasjunior" } [23]=> array(2) { ["fieldoption"]=> string(17) "student_ID_format" ["value"]=> string(1) "1" } [24]=> array(2) { ["fieldoption"]=> string(13) "updateversion" ["value"]=> string(4) "3.00" } } (05-10-2017, 04:17 AM)kayinja.denis Wrote:(05-10-2017, 03:48 AM)InsiteFX Wrote: Show a dump of the object or array that is returned from your query.Quote:array(25) { [0]=> array(2) { ["fieldoption"]=> string(7) "address" ["value"]=> string(22) "p.o box 2 njeru uganda" } [1]=> array(2) { ["fieldoption"]=> string(10) "attendance" ["value"]=> string(3) "day" } [2]=> array(2) { ["fieldoption"]=> string(10) "automation" ["value"]=> string(1) "5" } [3]=> array(2) { ["fieldoption"]=> string(21) "auto_invoice_generate" ["value"]=> string(1) "0" } [4]=> array(2) { ["fieldoption"]=> string(13) "backend_theme" ["value"]=> string(5) "basic" } [5]=> array(2) { ["fieldoption"]=> string(13) "currency_code" ["value"]=> string(3) "UGX" } [6]=> array(2) { ["fieldoption"]=> string(15) "currency_symbol" ["value"]=> string(2) "/=" } [7]=> array(2) { ["fieldoption"]=> string(5) "email" ["value"]=> string(30) "[email protected]" } [8]=> array(2) { ["fieldoption"]=> string(16) "fontendorbackend" ["value"]=> string(1) "1" } [9]=> array(2) { ["fieldoption"]=> string(13) "fontend_theme" ["value"]=> string(5) "basic" } [10]=> array(2) { ["fieldoption"]=> string(13) "fontorbackend" ["value"]=> string(1) "0" } [11]=> array(2) { ["fieldoption"]=> string(6) "footer" ["value"]=> string(28) "Copyright ©florasjunior" } [12]=> array(2) { ["fieldoption"]=> string(16) "google_analytics" ["value"]=> string(0) "" } [13]=> array(2) { ["fieldoption"]=> string(8) "language" ["value"]=> string(7) "english" } [14]=> array(2) { ["fieldoption"]=> string(6) "mark_1" ["value"]=> string(1) "1" } [15]=> array(2) { ["fieldoption"]=> string(6) "mark_3" ["value"]=> string(1) "0" } [16]=> array(2) { ["fieldoption"]=> string(4) "note" ["value"]=> string(1) "1" } [17]=> array(2) { ["fieldoption"]=> string(5) "phone" ["value"]=> string(13) "+256789960188" } [18]=> array(2) { ["fieldoption"]=> string(5) "photo" ["value"]=> string(132) "a8240c1de32628b9ad6a2fae89c2eb4013da24573fd810e49248eae383bf15442178739622ae9f9f9ab93c3f329f6e284cb239942fc9225b24b6c1c1978700c5.png" } [19]=> array(2) { ["fieldoption"]=> string(13) "purchase_code" ["value"]=> string(36) "f541d688-9d40-40db-99fb-65e6f80692ab" } [20]=> array(2) { ["fieldoption"]=> string(11) "school_type" ["value"]=> string(9) "classbase" } [21]=> array(2) { ["fieldoption"]=> string(11) "school_year" ["value"]=> string(1) "1" } [22]=> array(2) { ["fieldoption"]=> string(5) "sname" ["value"]=> string(12) "florasjunior" } [23]=> array(2) { ["fieldoption"]=> string(17) "student_ID_format" ["value"]=> string(1) "1" } [24]=> array(2) { ["fieldoption"]=> string(13) "updateversion" ["value"]=> string(4) "3.00" } } You dont have column with name "sname". Column names is fieldoption and value. So you need to create a function that will get the value of the column "valuae" for the line where the fieldoption equal to the value specified by you. Example: PHP Code: <?php AND render: Code: <h1><?=get_school()?</h1>
Here is a nice method to format var_dump values.
PHP Code: /** Will make it easier to read in the forum's hers. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-10-2017, 12:06 PM)InsiteFX Wrote: Here is a nice method to format var_dump values.bro i don't understand how to use your function... |
Welcome Guest, Not a member yet? Register Sign In |