Welcome Guest, Not a member yet? Register   Sign In
array problem
#1

[eluser]junaids[/eluser]
hi.
i m trying to get data from two models functions and pass it to a view. one model is working correct while the other is returning strange data..
my model is
Code:
function geteventdata($validevent)
    {
    $this->db->select('*')->from('event')->where('Event_ID', $validevent);
    $eventresult = $this->db->get();
    $eventrow = $eventresult->row_array();
    return $eventrow;
    }
    
    function geteventcomments($validevent)
    {
    $this->db->from('event_comments')->where('Event_ID', $validevent);
    $commentresult = $this->db->get();
    $commentrow = $commentresult->row_array();
    return $commentrow;
    $commentresult->free_result();
    }

and my controller is
Code:
$validevent = $Event_id;
        $eventdata = $this->eventsmodel->geteventdata($validevent);
        $data['eventdata'] = $eventdata;
        // get event comments
        $eventcomments = $this->eventsmodel->geteventcomments($validevent);
        $data['eventcomments'] = $eventcomments;
        $this->load->view('events/viewevent', $data)
now in the view the 'eventdata' is returning correct data.. as there are multiple comments for an event so i have used a foreach loop to display them...
Code:
<?php foreach ($eventcomments as $row): ?>
                  <tr>
                    <td height="22" align="left" valign="top" class="txt">Comment&nbsp;:&nbsp;&lt;?php echo $row['Comment_msg']; ?&gt;</td>
                  </tr>
                  &lt;?php endforeach; ?&gt;
but i m getting output like

Comment : 9
Comment : 2
Comment : a
Comment : 0
Comment : 1

where in DB the Comment_msg are not numeric..any help plz..
#2

[eluser]TheFuzzy0ne[/eluser]
First of all, the $commentresult->free_result() call will never actually happen, as the function returns beforehand.

You'll need to debug the returned array with something like this:
Code:
die('<pre>'.print_r($eventcomments, TRUE).'</pre>');

Please post back with your findings.

I'd also like to point out that your variables and method names are quite difficult to read. They might be better off written like this:
Code:
$this->events_model->get_event_comments($valid_event); # And so on...
#3

[eluser]junaids[/eluser]
i got it right by changing
Code:
$commentrow = $commentresult->row_array();

to

Code:
$commentrow = $commentresult->result_array();

thanks for ur sugestions...i will change function names....i myself cant read them quickly.




Theme © iAndrew 2016 - Forum software by © MyBB