Welcome Guest, Not a member yet? Register   Sign In
Strange problem with CI and oracle (longish) Please help!!
#1

[eluser]dpgtfc[/eluser]
Let's see if I can explain this well enough. I have a function that lists classes (as in school, not programming) in a particular category, all of which is stored in an oracle database. We are using 10g, with php 4.3.

I have a function like thus:

Code:
function list_classes($cid,$semester)
    {
        
        $arr2 = array();
        $sql = "SELECT * FROM MyDB.AED_CLASSES
                WHERE (CLASSTYPE=? AND CLASSSTATUS LIKE 'OPEN' AND SEMESTER LIKE ?)
                ORDER BY CLASSID DESC";
        
        $query2 = $this->db->query($sql,array($cid,$semester));
        $i = 0;
        foreach($query2->result_array() as $data)
        {
            $arr2['classes'][$i]['CLASSID'] = $data['CLASSID'];
            $arr2['classes'][$i]['TITLE'] = $data['TITLE'];
            $arr2['classes'][$i]['SEMESTER'] = $data['SEMESTER'];
            $arr2['classes'][$i]['CSECTION'] = $data['CSECTION'];
            $i++;
            
            $arr2['msg'] = "$cid";
        }
        return $arr2;
    }


I have a controller called test, which pulls this data just fine, here is the test controller and view:

Code:
$arr = $this->cat->list_classes('1','Fall 2008');
       $this->parser->parse('content/test_view', $arr);
Code:
{classes}    
       <strong>Title</strong> {TITLE}<br/>
       <strong>Semester</strong> {SEMESTER}<br/>
       <strong>Section</strong> {CSECTION}<br/><hr/>
        
{/classes}

This works fine! so when I move it into the proper controller, it no longer works!

Here is my controller that doesn't work, with the portion of the view that is relevant:

Code:
function category()
    {
        if($this->auth_model->is_logged_in())
        {  
            //////////////////////////////////
            ///  If delte button is pressed, it redirects back to the same page and new list is shown
            //////////////////////////////////
            if($this->input->post('classid') !== false)
            {
                $this->cat->delete_class($this->input->post('classid'));
            }
            
            $catid = $this->input->post('category');  // category id is set
            $category = $this->cat->get_category_name($this->input->post('category')); // category name is set
            ///////////////////////////////////
            ///  Arr array is initialized with classes in the category selected.
            ///////////////////////////////////
            $arr = $this->cat->list_classes($catid,$_SESSION['semester']);
            $arr['title'] = "$category Classes"; // page title set
            $arr['cid'] = $catid;
            
            $data = set_home();  
            $data['pg_title'] = $category;
            $data['main_content']= $this->parser->parse('content/classes_category_view', $arr, TRUE);
            $this->parser->parse('templates/index', $data);    
        }
        else{redirect('');}
    }
Code:
<center>
<table>
    <tr>
        <th width='40%'>Class Title</th>
        <th width='20%'>Semester</th>
        <th width='20%'>Section #</th>
        <td width='10%'></td>
        <td width='10%'></td>
    </tr>
{classes}    
    <tr>
        <td>{TITLE}</td>
        <td align='center'>{SEMESTER}</td>
        <td align='center'>{CSECTION}</td>
        <td valign='top'>
            &lt;form name='edit' action='&lt;?= site_url('manage/edit') ?&gt;' method='POST'&gt;
            &lt;input type="hidden" name="classid" value="{CLASSID}"/&gt;
            &lt;input type='submit' name='edit' value='edit' style='width:50px'&gt;&lt;/form>
        </td>
        <td valign='top'>
            &lt;form name='del' action='&lt;?= site_url('manage/del') ?&gt;' method='POST'&gt;
            &lt;input type="hidden" name="classid" value="{CLASSID}"/&gt;
            &lt;input type="hidden" name="category" value="{cid}"/&gt;  
            &lt;input type='submit' name='delete' value='delete' style='width:50px'&gt;&lt;/form>
        </td>
    </tr>
{/classes}    
</table>
</center>

for the life of me I cannot see the issue. I have troubleshot this for several hours and cannot find any errors. The error I get is the following:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined index: CLASSID

Filename: models/category_model.php

Line Number: 34

This is only one of the errors, all of values in my model give an error, classid, title, etc.

Argh, I'm about ready to give up to be honest. If I convert the model back to how I had it before, magically it works so the controller can't be broken, right? Old function code:

Code:
$conn = o_connect();
        $sql = "SELECT * FROM MyDB.AED_CLASSES
                WHERE (CLASSTYPE='$cid' AND CLASSSTATUS LIKE 'OPEN' AND SEMESTER LIKE '$semester')
                ORDER BY CLASSID DESC";
        
        $stmt = ociparse($conn,$sql);
        ociexecute($stmt);
        $i = 0;  
        while(ocifetchinto($stmt,$data, OCI_ASSOC))
        {              
            $arr['classes'][$i]['CLASSID'] = $data['CLASSID'];
            $arr['classes'][$i]['TITLE'] = $data['TITLE'];
            $arr['classes'][$i]['SEMESTER'] = $data['SEMESTER'];
            $arr['classes'][$i]['CSECTION'] = $data['CSECTION'];
            $i++;
        }
        $arr['msg'] = "";
        
        return $arr2;
#2

[eluser]dpgtfc[/eluser]
Uhhh, ok, so I just now upgraded to 1.7 and it fixed the problem somehow.

I would be interested in hearing an explanation though, in case somebody knows what was wrong.




Theme © iAndrew 2016 - Forum software by © MyBB