Welcome Guest, Not a member yet? Register   Sign In
Passing data to view?
#1

[eluser]PHP Creative[/eluser]
Hi there

Really stuck on this. How would I passing the following to the view from the controller?

Code:
$ans1[$i] = $row[2];
$ans2[$i] = $row[3];
$ans3[$i] = $row[4];

Thanks a million
#2

[eluser]stuffradio[/eluser]
First of all, this code doesn't make sense. I think you're breaking the MVC pattern already. Show us more of the code that you have so we can better determine what you're doing and help you.
#3

[eluser]PHP Creative[/eluser]
Code:
$answer = array();
        $question = array();
        $qnum = array();
        $orgid = array();
        $i = 0;



   $query = "SELECT * from test ORDER by RAND() LIMIT 20";
        $result = mysql_query($query, $db);
        
        while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
        
        
        $answer[$i] = $row[5];
        $question[$i] = $row['1'];
        $qnum[$i] = $i;
        $orgid[$i] = $row['id'];
        
        
        $ans1[$i] = $row[2];
        $ans2[$i] = $row[3];
        $ans3[$i] = $row[4];
#4

[eluser]stuffradio[/eluser]
I hope this isn't in your controller file. Is it in your Model or Controller?
#5

[eluser]bretticus[/eluser]
[quote author="PHP Creative" date="1260681321"]How would I passing the following to the view from the controller?

Code:
$ans1[$i] = $row[2];
$ans2[$i] = $row[3];
$ans3[$i] = $row[4];
[/quote]

Like this...

Code:
$data['ans2'] = $ans2;
$data['ans3'] = $ans3;
$this->load->view('view_file', $data);

...but I think you are missing the point of CodeIgniter. I see nothing in your code that represents any of the framework goodies built into CI. For example, even though you don't need a model I suppose, you could load the query results from a model file (that actually uses framework conveniences like Active Record!) From there you can simply pass the resulting object to your view and iterate over the database records without using arrays to hold the information.

This post should probably be moved to Code...
#6

[eluser]PHP Creative[/eluser]
Thanks a million

That’s an excellent idea and will use the active record goodies.

I'm currently rewriting an old site someone else coded using the CI framework so it can be a bit difficuilt at times without completey destroying the old code

Thanks again Smile




Theme © iAndrew 2016 - Forum software by © MyBB