Welcome Guest, Not a member yet? Register   Sign In
How to output database to table formated into rows and columns
#7

[eluser]brandontran[/eluser]
[quote author="WanWizard" date="1251572903"]The main reason for putting your I/O code in a model is that is it easy to reuse, and it hides complexity from your controllers. It also allows you to make changes to your database environment, without affecting your controller code (as long as you don't change the return values of the methods in your model).

In your case, create a model, and in that model a method called get_my_pics(). You could pass some variables to the method if you want to make selections, run the query, and have the method return the $query->result().

In the above example, you could then use:
Code:
<? foreach ($this->mymodel->get_my_pics() as $i=>$row): ?>

Also, I don't think comparing $i to "3" (which is a string) is a good idea. And what happens if $i gets to 7? Another issue is that if the query returns an exact multiple of four, you end up with an empty table row with no cells, which doesn't validate.

This is from the top of my head, there are probably better solutions. Also, I never mix html and php (I don't use views), so I'm not sure of the correct syntax.[/quote]

There is a limit on the pull. It's an 8 photo template for the site. So I just needed it split at 4 entries, new row and 4 more entries. So it won't ever go over 8 unless we redesign the template. Now that fact you made about $i being a string. In the old php method of coding with while loops $i=0; and $i++ it was a variable so that was my thinking. But it concerns me it being a string in this aspect. I need to look into that to make sure and find out what the right technique will be. We will be doing some testing to make sure it processes fast before all is said and done.


Messages In This Thread
How to output database to table formated into rows and columns - by El Forum - 08-29-2009, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB