mysql_fetch_row() in CodeIgniter |
[eluser]punchi[/eluser]
Code: <?php Source: http://cl.php.net/manual/en/function.mys...ch-row.php ---- I have a code like this (just an example): Code: <? But because I change sometimes the SQL for other pages, I NEED something like the fetch_row, and make possible something like this: Code: <? In the User Guide, I didn't find anything... any trick? it's possible? its maybe a Feature Requests? =O thanks people! =D
[eluser]skunkbad[/eluser]
how about result_array() ? I know you are looking for numberic indices, so perhaps you can extend the method?
[eluser]umefarooq[/eluser]
here is the user guide link for your problem. http://ellislab.com/codeigniter/user-gui...sults.html
[eluser]punchi[/eluser]
[quote author="skunkbad" date="1260702146"]how about result_array() ? I know you are looking for numberic indices, so perhaps you can extend the method?[/quote] This code: Code: <? Doesn't work. What you mean with extend the method? Modify the core of CodeIgniter? [quote author="umefarooq" date="1260709217"]here is the user guide link for your problem. http://ellislab.com/codeigniter/user-gui...sults.html[/quote] My friend, its the SAME link I provided (read my post) where I didn't find any solution.
[eluser]skunkbad[/eluser]
[quote author="umefarooq" date="1260709217"]here is the user guide link for your problem. http://ellislab.com/codeigniter/user-gui...sults.html[/quote] The OP's problem is, there is no result method that will produce an array with numeric indices. In plain PHP, mysql_fetch_array returns BOTH numeric and associative indices, but CI's result_array() only returns associative indices.
[eluser]skunkbad[/eluser]
I was looking at the manual, and you might be able to use: http://ellislab.com/codeigniter/user-gui...ction.html
[eluser]jedd[/eluser]
[quote author="punchi" date="1260745667"] Code: foreach ($query->result_array() as $row) Either a) reassess why you want to be able to this (as you might be happier to just use the normal array walking functions of PHP - like everyone else does), or b) in the model you can massage your return data to look like this (I really do prefer option (a))). For example: Code: $rows = $query->result_array();
[eluser]punchi[/eluser]
@skunkbad Thanks, I didn't saw that page =O... it works! =D however its too slow =/ ... the code its like this (NOTE: I must be done with mysql_query() and NOT with $this->db->query(), or it won't work) MODEL: Code: $sql = 'SELECT ID_PLAN, PL_NAME FROM plan'; The controller just pass the upper return to a "query" data VIEW: Code: foreach ($query as $row) It works fine but again, too slow =/ ------- @jedd Im happy to just use the normal array like everyone does, but the "normal array" is NOT the solution for every problem. I want to show the information as wrote in SQL, so, if my sql is SELECT X, Y, Z, i want to see X, Y, Z, and when I change to SELECT Y, Z, X, see the same order. And thanks jedd, but your solution didn't work, or I made a mistake... MODEL: Code: $sql = 'SELECT ID_PLAN, PL_NAME FROM plan'; VIEW: Code: print_r(array_count_values($query)); The error its enough to tell me that, there's no integer or string values (before have tried with $query[0], $query["PL_NAME"] and $query->PL_NAME too, all errors) ...Still can't get a good solution :down:
[eluser]punchi[/eluser]
My solution: Change Code: while($row = $this->db->call_function('fetch_row', $query)) { for Code: while($row = mysql_fetch_row($query)) { The page speed up a 350% (from 0.0035 to 0.0010). The differences between foreach ($query2 as $row) and foreach ($query->result() as $row) are insignificant. And now, between the "almost-always-used" Code: $sql = 'SELECT ID_PLAN, PL_NAME plan'; and Code: $sql = 'SELECT ID_PLAN, PL_NAME plan'; The last one, its 170% more efficient. Another reason Jedd ;-) What I don't know, if working with CodeIgnite and PHP native functions, have some incompatibilities or is inappropriate... Thanks! =)
[eluser]jedd[/eluser]
[quote author="punchi" date="1260755489"] Im happy to just use the normal array like everyone does, but the "normal array" is NOT the solution for every problem. I want to show the information as wrote in SQL, so, if my sql is SELECT X, Y, Z, i want to see X, Y, Z, and when I change to SELECT Y, Z, X, see the same order. [/quote] Hang on - you're saying that you want to ignore the ordering or your SQL function? Why not just get the ordering done properly in the first place? Quote:VIEW: I'm assuming that $query in your controller is taking the $retdata from the model? You didn't show the code - and I don't like assumptions. In any case, print_r() of $query here would be far more instructive, I suspect. What does sizeof() report? [quote author="punchi" date="1260759436"] The page speed up a 350% (from 0.0035 to 0.0010). [/quote] How big is your sampling set, and under what conditions? This differential seems pretty trivial at a glance. Quote:What I don't know, if working with CodeIgnite and PHP native functions, have some incompatibilities or is inappropriate... What kind of incompatibilities are you thinking of here? I think they'd probably have noticed if such things existed by now. ![]() |
Welcome Guest, Not a member yet? Register Sign In |