Welcome Guest, Not a member yet? Register   Sign In
Query Issue
#1

[eluser]Funky Fresh[/eluser]
Hey All,

Im having a bit of difficulty with a query im trying to perform.

I want to retreive all details for a file stored in the database.

in my model, i have the following code.

Code:
function getFileInfo($transferid)
    {
        $data = array();
        $this->db->select('1', FALSE);
        $this->db->where('transferid', $transferid);
        
        $query = $this->db->get(self::TABLE_IDX);
        if($query->num_rows() > 0){
            $data = $query->row_array();
        }
        $query->free_result();
        return $data;
    }

In my controller i have the following

Code:
$data['fileinfo'] = $this->Idxfiles_model->getFileInfo($transferid);

Everything i try in my view to output the results, for example the name, doesnt seem to be working.

Can someone please help me out on where im going wrong.

Cheers,
#2

[eluser]InsiteFX[/eluser]
Try this:

Code:
$this->db->select('1', FALSE);
// the '1' above should be the table field name.

// change this:
$query = $this->db->get(self::TABLE_IDX);

// to this:
$query = $this->db->get('TABLE_IDX');

// also I do not see were you are setting $transferid?
$this->db->where('transferid', $transferid);

View:
Code:
foreach ($fileinfo as $key => $item)
{
    // fieldname would be the table field name.
    echo $item['fieldname'] . "\n";
}

echo "<br/><br/>";

What your doing is assigning the returned $row_array();
to the $data['fileinfo']; array, so in your view you
need to loop through the items and display them.

I'll be up most of the night so if you need more help
just post here.

InsiteFX
#3

[eluser]theprodigy[/eluser]
Quote:// also I do not see were you are setting $transferid?
$this->db->where('transferid', $transferid);

He's passing it in as a parameter to the function.
#4

[eluser]Funky Fresh[/eluser]
Hey InsiteFX,

I added the foreach loop to the view, but anything just returns a 1
#5

[eluser]erik.brannstrom[/eluser]
InsiteFX had the comment "the '1' above should be the table field name", meaning you have to write something like $this->db->select('id, name') instead of just the '1'.
#6

[eluser]InsiteFX[/eluser]
If you can post your database schema and give an example of
what you want to do I am sure we get you going in the right
track.

Table name
Field names
etc

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB