![]() |
FORMATTING QUESTION - QUERY & MODEL - 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: FORMATTING QUESTION - QUERY & MODEL (/showthread.php?tid=55704) |
FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-06-2012 [eluser]Barwick[/eluser] I currently have this in my controller (works and functions as I need it too). Individually grabs a row (3 rows in total) from a "pricing" table and displays the info throughout 3 packages in the view. (1) My first question - is there any easier way to write this? Or better question, how do I simplify this? I need 3 sets of different variables to display in the view... (2) Second question - considering this is a database call, it should likely go in the model. However, I need to send variables to the view. How would I create a model function for this instead? Allowing me to send the necessary variables to my view... Code: // Pricing and package details insert from db FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-06-2012 [eluser]jprateragg[/eluser] You could just save the result to an array: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-06-2012 [eluser]Barwick[/eluser] [quote author="jprateragg" date="1352263616"]You could just save the result to an array: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); Wouldn't I then need to define each row still though? FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-06-2012 [eluser]n_uryanto[/eluser] wow thnaks for ur answer for problem. i have problem same for you. nuryanto FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]Aken[/eluser] [quote author="Barwick" date="1352264580"][quote author="jprateragg" date="1352263616"]You could just save the result to an array: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); Wouldn't I then need to define each row still though?[/quote] It depends how you're accessing the data in your views. If you need them in individual, separate parts of your view, then using result() or result_array() might not be very efficient. If you can do a foreach() in your view, then those methods would be more appropriate. FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]Barwick[/eluser] [quote author="Aken" date="1352278042"][quote author="Barwick" date="1352264580"][quote author="jprateragg" date="1352263616"]You could just save the result to an array: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); Wouldn't I then need to define each row still though?[/quote] It depends how you're accessing the data in your views. If you need them in individual, separate parts of your view, then using result() or result_array() might not be very efficient. If you can do a foreach() in your view, then those methods would be more appropriate.[/quote] I need them in separate parts unfortunately. So I guess I'm stuck with several extra lines of code then. Just don't want to develop bad or incorrect CI habits. Hence odd question like this one. ![]() FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]boltsabre[/eluser] You could wrap your three assigns inside a loop, reducing the need to "copy/paste" and manually update the number. Saves a few lines of code and it less prone to bug... FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]Barwick[/eluser] [quote author="boltsabre" date="1352299267"]You could wrap your three assigns inside a loop, reducing the need to "copy/paste" and manually update the number. Saves a few lines of code and it less prone to bug...[/quote] How do you mean? code example? FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]PhilTem[/eluser] You could do this fancy thing: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); and in your view Code: $item1 = $items->row(0); Or, to make it a little less "let's put a db resource handle object into our view" do it like this Code: $this->db->select('title, price, number_sites, number_entries, white_label'); which will give you as well access to Code: echo $item2->title; PS: The second example is just a short version of your originally posted code ![]() FORMATTING QUESTION - QUERY & MODEL - El Forum - 11-07-2012 [eluser]Barwick[/eluser] [quote author="PhilTem" date="1352302135"]You could do this fancy thing: Code: $this->db->select('title, price, number_sites, number_entries, white_label'); and in your view Code: $item1 = $items->row(0); Thanks! This works...but leaning the framework, this is probably not the best route. I'll forget what this means lol. Or, to make it a little less "let's put a db resource handle object into our view" do it like this Code: $this->db->select('title, price, number_sites, number_entries, white_label'); which will give you as well access to Code: echo $item2->title; PS: The second example is just a short version of your originally posted code ![]() |