Welcome Guest, Not a member yet? Register   Sign In
$query->row_array() problem
#1

[eluser]blorriman[/eluser]
I have a poll with a radio group showing the answers (from a db table 'poll_answer.

When the user selects one of the answers I return the radio button number (ie: 1,2,3, etc), which corresponds to the row of the answer in the table.

I am trying to use $query->row_array() - with the radio button number inside the brackets to find the row in the table.

$uri_3 is the radio button number
$pq_id is the id of the question the answers are associated with.

With the following code:
Code:
$uri_3 = '3';
$pq_id = '15';

    $query = $this->db->get_where('poll_answer', array('pq_id' => $pq_id));
    foreach ($query->result() as $row) {
        echo $row->id . ' - ';
        echo $row->answer . '<br>';
    }

I get all the answers as they are in the table (the number is their id), so I know it is working:
Quote:29 - I think so
30 - I'm not sure
31 - I don't think so

However, since I only want the one answer that corresponds to the radio button selected, I am trying to use the following code:
Code:
$uri_3 = '3';
$pq_id = '15';

    $query = $this->db->get_where('poll_answer', array('pq_id' => $pq_id));

    $row = $query->row_array($uri_3);
    echo $row['id'] . ' - ';
    echo $row['answer'] . '<br>';
But when I change the $uri_3 I get the following:
Quote:$uri_3 = 1 - "30- I'm not sure"
$uri_3 = 2 - "31 - I don't think so"
$uri_3 = 3 - "29 - I think so"

So it's completely out of order. $uri_3 = 1 should give the first row, but instead returns the second row, $uri_3 = 2 should be the second row, but instead returns the third row, and $uri_3 = 3 returns the first row.

Any suggestions?


Messages In This Thread
$query->row_array() problem - by El Forum - 11-09-2010, 12:21 PM
$query->row_array() problem - by El Forum - 11-09-2010, 12:51 PM
$query->row_array() problem - by El Forum - 11-09-2010, 12:55 PM
$query->row_array() problem - by El Forum - 11-09-2010, 01:51 PM
$query->row_array() problem - by El Forum - 11-09-2010, 01:58 PM
$query->row_array() problem - by El Forum - 11-09-2010, 02:08 PM
$query->row_array() problem - by El Forum - 11-09-2010, 02:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB