Problems With My Code Extra Set of Eyes Needed!! |
[eluser]codedoode[/eluser]
I'm having a problem getting a getting two separate MySQL tables to display on one page. This is my controller code Code: function index() This is my model code Code: function get_records() This is my view Code: <!-- start post --> I'm assuming it's a problem with the way I'm writing my If statements on the view page, but then again I have no idea. This is one of maybe issues I'm running into when putting the finishing touches on this new website I'm building. Can anyone help me get this working or provide insight as to why this isn't working? THANK YOU TO ANYONE WHO HELPS IN ADVANCE!
[eluser]mikegeorgeff[/eluser]
Try this: Controller Code: function index() View Code: <div class="post"> I think the problem is when you call $this->load->view() it only accepts one variable so you need to tie both your model functions to on variable, which is the $data variable in the above example.
[eluser]crnalajna[/eluser]
First of all, it's not a proper way of using view call. Vars are not transferred to your view as it should. Please read carefully http://ellislab.com/codeigniter/user-gui...views.html For debugging you can always use var_dump() in your view or controller file.
[eluser]codedoode[/eluser]
[quote author="mikegeorgeff" date="1297153045"]Try this: Controller Code: function index() View Code: <div class="post"> I think the problem is when you call $this->load->view() it only accepts one variable so you need to tie both your model functions to on variable, which is the $data variable in the above example.[/quote] This didn't work at all Anyone else have any ideas
[eluser]jakub[/eluser]
@codedoode, what is the actual 'issue' are you having a code problem? As in bug? Or are you trying to wrap your head around how to do what you want (which is output data from 2 tables?). Please clarify your question, tell us what the issue is, and what you expect.
[eluser]codedoode[/eluser]
@jakub. I'm trying to wrap my head around how to do what I want to do (which is output the data from 2 tables) The only thing that is not outputting is what's in the votes ul. It's returning "No votes were found." instead of the db data
[eluser]d1a8lo24[/eluser]
The following example is following your code to correct the output not the logic. First lets do the model Code: function get_records() Now lets work with the controller Code: function index() Now on your view you can do the following. Code: // Now you can loop through your arrays. Now it seems that you want to get all the users records and also get each user's votes, if this is the case then your coding logic is wrong. In the other hand if you're trying to get all users records and display some voting options then your code looks ok. If your case is the first one this is why your code logic is wrong. When executing your first loop everything looks fine but your second inner loop is the one that is going to cause you problems. When the second loop executes it will loop through every vote record but it will do this for every user record. This means that every user will have a list of everyone's votes. And i think this is not what you want. To fix this you need to change your code logic in your model. |
Welcome Guest, Not a member yet? Register Sign In |