Welcome Guest, Not a member yet? Register   Sign In
capture id on click
#11

@ryan, take notice that the anchor function already generates the <a> and </a> tags, so don't add those yourself.
This:
PHP Code:
echo anchor('controllerName/syllabus/'.$row->ID'button label'); 
has this output:
<a href="controllerName/syllabus/x">button label</a>

And as PaulID suggested, don't put the <li> tags inside the anchor, but around it, like this:

PHP Code:
echo '<li> . anchor('controllerName/syllabus/'.$row->ID, 'button label') . '</li>'; 
Reply
#12

(This post was last modified: 01-04-2016, 08:48 PM by ryan.)

So I was wrong in saying this was solved. I realized it was generating page/1, page/2, page/3. I didn't realize at the time that isn't what I was looking for. It seems that I want to put the ID into the WHERE part of the sql statement. I got the controller to talk to the model but cant get the view to talk to the controller. In JS I would have the onClick function return an argument but I don't know how to do this with .anchor function. I was thinking maybe putting it in one of the attributes but that seemed dirty.

I will fix the anchor tags tomorrow at work.



controller
Code:
public function index()
    {
        $this->home();
    }
    
    public function home()
    {        
        $data['title'] = 'Give Me a Title';
        $data['page_header'] = 'Give me a Page Header';
        $this->load->model('model_get');
        $data['results']=$this->model_get->getMDS();
        
        $this->load->view('site_header', $data);
        $this->load->view('content_home',$data);
        $this->load->view('site_footer');
    }
    
    public function soi()
    {
        $data['title'] = 'Give Me a Title';
        $data['page_header'] = 'Give me a Page Header';
        $this->load->model('model_get');
        $data['results']=$this->model_get->getSOI(1);
        
        $this->load->view('site_header', $data);
        $this->load->view('content_soi',$data);
        $this->load->view('site_footer');
    }

view

Code:
<ul>
<?php
    foreach($results as $row)
    {
        echo '<a>'.anchor('site_controller/soi/', '<li>'.$row->name.' - '.$row->niceName.'</li>').'</a>';//I'm thinking of how to
                                                                                                                 //make this return $row
                                                                                                                 //-> ID and feed it to
                                                                                                                 //function soi
    }
?>
</ul>    

<button class='close'>Close</button>
//model
Code:
function getMDS()
{
      $query = $this->db->query("SELECT * FROM tbl_mds");
      return $query->result();
}
    
function getSOI($mds_ID)
{
      $query = $this->db->query("SELECT * FROM lnk_soi WHERE mds_ID=$mds_ID");
      return $query->result();
}

Thanks to you all for your help.
Reply
#13

(This post was last modified: 01-05-2016, 07:24 AM by ryan.)

I think my explanation is still bad. Hoping this image helps.


******edit****

I just got to thinking im an idiot. I keep thinking of this as a function call to public function soi() but the function call is behind the scene. I'm thinking I need to do an onClick function call with JS or something to be able to pass the argument.

Attached Files Thumbnail(s)
   
Reply
#14

PHP Code:
public function soi($id)
 
   {
 
       $data['title'] = 'Give Me a Title';
 
       $data['page_header'] = 'Give me a Page Header';
 
       $this->load->model('model_get');
 
       $data['results']=$this->model_get->getSOI($id);
 
       
        $this
->load->view('site_header'$data);
 
       $this->load->view('content_soi',$data);
 
       $this->load->view('site_footer');
 
   

PHP Code:
foreach($results as $row)
 
   {
 
       echo '<a>'.anchor('site_controller/soi/'.$row->id'<li>'.$row->name.' - '.$row->niceName.'</li>').'</a>';
 
   
Reply
#15

I swear I tried that .... I think I was skirting around that solution but was making my mistake at
Code:
$data['results']=$this->model_get->getSOI($id);

I think I was trying to create my own variable name or something like $test instead of using $ID.

Thank you everyone for the help.
Reply
#16

(01-05-2016, 08:53 AM)ryan Wrote: I swear I tried that .... I think I was skirting around that solution but was making my mistake at
Code:
$data['results']=$this->model_get->getSOI($id);

I think I was trying to create my own variable name or something like $test instead of using $ID.

Thank you everyone  for the help.

Well, $id could be named anything you want really, but if it is an ID, why not call it ID?

If you were trying to get a record via a name, you'd use $name most likely?
Reply
#17

makes sense to me, I must have been screwing up elsewhere. I had got the id to show up in the url but it wasn't feeding to the WHERE part of SQL. All works now so I am happy.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB