• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI Noob having a problem...suprised?

#1
[eluser]dantrag1989[/eluser]
Hi Folks,
This is my first go around with CI so please be kind :-). I am trying to mash together something resembling one of my old projects in CI as I like the things that I have heard and seen from it. So far, its a bit slow going but I do see how once you understand it will be much faster. So anywho...
I have run into the following problem:
Quote:Parse error: syntax error, unexpected T_STRING in /usr/home/sburke2/public_html/demo/codeigniter/system/application/models/dbfunc_model.php on line 26
Simple right? Nope. I have commented out everything that is being called in dfunc_model and it is still throwing the error. I was hoping that you folks could at least point me in the right direction.

Here is the controller:
Code:
<?php
class Display_results extends Controller {

function index()
    {
        echo 'Here are your Results';
        $this->db->load('library');
    }

function results()
    {
        $this->load->model('dbfunc_model');
        $data['query'] = $this->dbfunc_model->display_list();
        
        $this->load->view('results', $data);
    }




}
?>

Model:
Code:
<?php
class dbfunc_model extends Model
{
  function dbfunc_model()
  {
    parent::Model();
  }

  function insert_update()
  {
    $this->load->database('library');
    $data = array('upload_data' => $this->upload->data());
    $file_path = $data['upload_data']['file_name'];
    $time=now();
    $name = $this->input->post('title');
    $cat = $this->input->post('catagory');
    $descrip = $this->input->post('description');
      
    $sql = "INSERT INTO library (name, cat, descrip, path, timestamp) VALUES(?, ?, ?, ?, ?)";
    $this->db->query($sql, array($name, $cat, $descrip, $file_path, $time));
  }
  
  function display_list()
   {
       //$this->load->database('library');
       $query = $this->db->query(SELECT * FROM library);
        return $query;
        //$sql = "SELECT * FROM library WHERE cat=Training";
        //$this->db->query($sql);
      
   {


}
?>

and the View:
Code:
<table>
    <tr>
        <th>ID</th>
        <th>Title</th>
        <th>Catagory</th>
        <th>Description</th>
        <th>File Path</th>
        <th>Uploaded</th>
        
    </tr>
&lt;?php
if($query->num_rows() > 0):
   foreach ($query->result() as $row):
?&gt;    
    <tr>
        <td>&lt;?php echo $row->id; ?&gt;</td>
        <td>&lt;?php echo $row->name; ?&gt;</td>
        <td>&lt;?php echo $row->cat; ?&gt;</td>
        <td>&lt;?php echo $row->descrip; ?&gt;</td>
        <td>&lt;?php echo $row->path; ?&gt;</td>
        <td>&lt;?php echo $row->timestamp; ?&gt;</td>
    </tr>
&lt;?php
    endforeach;
endif;
?&gt;
</table>

Any help would be appreciated.

#2
[eluser]mironcho[/eluser]
In your model, display_list() function, the closing curly bracket is looking in the wrong direction (should be } ).

#3
[eluser]dantrag1989[/eluser]
Yes it was. But unfortunately that did not fix the problem. The error message remains.

#4
[eluser]elvix[/eluser]
maybe try quoting your sql query? ("Select ...")

#5
[eluser]crumpet[/eluser]
Yeah i think you need to have quotes around your query. Also make sure your autoloading the database library in your autoload conf file.

Have you looked at the active record class? Its a little more code but its so easy to write queries its worth it.

//$sql = "SELECT * FROM library WHERE cat=Training";

would be

$this->db->where('cat', 'Training');
$query = $this->db->get('library');

if you don't want to SELECT * you can use
$this->db->select('name, color, etc');

#6
[eluser]dantrag1989[/eluser]
[quote author="crumpet" date="1215723902"]Yeah i think you need to have quotes around your query. Also make sure your autoloading the database library in your autoload conf file.

Have you looked at the active record class? Its a little more code but its so easy to write queries its worth it.

//$sql = "SELECT * FROM library WHERE cat=Training";

would be

$this->db->where('cat', 'Training');
$query = $this->db->get('library');

if you don't want to SELECT * you can use
$this->db->select('name, color, etc');[/quote]

Yeah looks like it was combo of the curly brace and the quotes lol. Its the little things that trip you up...well they always trip me up lol. Thanks for all your help guys!

@Crumpet
I was looking at that earlier and was planning on moving to that once I found my mistake. I eventually want to change Training to a variable so I don't have to write a function for each category. Thanks for your help again!

#7
[eluser]dantrag1989[/eluser]
Ok now I have another question. It pulls 'path' from the database as the new file name. What I need to have happen is for it to make that into a link. The file is located in a directory outside of the domain root. I have looked through the documentation but I was unable to find instructions on how to accomplish that.

#8
[eluser]Colin Williams[/eluser]
Look into the url helper for anchor() and/or site_url()


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.