Welcome Guest, Not a member yet? Register   Sign In
Help pasing variable from one function to another in same controller.
#11

[eluser]debow[/eluser]
I get nothing back from your test query. I fixed the typo and with my query I get nothing but I do if I use this.

Code:
$event = $e != ''; //This returned all events that had a space in them except for "100m Swim" and "1 Mile", ie:(Long Jump, Med Ball, Pull Ups, Push Ups, Shuttle Run, Wall Sits)
#12

[eluser]debow[/eluser]
Also, I'm not sure why if echo $e returns the value I'd expect why doesn't the query work with just using $e or $event = $e?
#13

[eluser]toopay[/eluser]
This is the code i pointed to...
[quote author="toopay" date="1305236026"]Just try this something like this to check if your database generates some result or not
Code:
//...
    public function test()
    {
        var_dump($this->ext_get_all('100m Swim'));
    }

    public function ext_get_all($e)
    {        
        $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 10;

        $query = $this->db->from('eresults')
                          ->where('event', $e)
                          ->order_by('event')
                          ->limit($limit, $start)
                          ->get();

        return $query->result_array();
    }
//...

Call test function to see the result.[/quote]

About the tenary i gave :

Code:
$event = $e != '' ? $e : 'default_event';

is equal with

Code:
if($e != '')
{
   $event = $e;
}
else
{
   $event = 'default_event';
}

change it into

Code:
$event = $e != '';

will make it have no affect anymore!
#14

[eluser]debow[/eluser]
From the most resent test you gave I get the following dumped to the screen.



array(1) { [0]=> array(14) { ["id"]=> string(3) "541" ["athlete_id"]=> string(3) "210" ["event"]=> string(9) "100m Swim" ["gender"]=> string(3) "men" ["result"]=> string(0) "" ["mins"]=> string(1) "1" ["secs"]=> string(2) "59" ["msecs"]=> string(3) "0.8" ["totalsecs"]=> string(5) "119.8" ["date"]=> string(4) "2011" ["eventrank"]=> string(0) "" ["eventscore"]=> string(0) "" ["eorder"]=> string(1) "1" ["name"]=> string(12) "John Doe" } }
#15

[eluser]toopay[/eluser]
Then it work right? Working on it then... And, put some db function like 'ext_get_all' on your model instead on your controller.
#16

[eluser]debow[/eluser]
I've taken the function ext_get_gall and placed it in a model. Now I get NULL on the return. But the echo $e works.

controller.php
Code:
public function index()
    {
        if ((isset($_GET['id']))) {
            $id = $_GET['id'];
            $data['gridevent'] = $id;          
        } elseif ((!isset($_GET['id']))) {
            $id = '';
            $data['gridevent'] = $id;
        }
        if ($data['gridevent'] == "1") {          
            $data['etitle'] = $this->data['swimtitle'];  
            $e = $this->test('100m Swim');
        } elseif ($data['gridevent'] == "2") {
            $e = $this->test('Pull Ups');
            $data['etitle'] = $this->data['pulltitle'];
        }

      $this->load->view('includes/header', $this->data);
      $data['main_content'] = 'results/results_edit_grid';
      $this->load->view('includes/template', $data);
    }
    
   function test($e){
      
       $this->Results_model->ext_get_all($e);
   }

model.php
Code:
function ext_get_all($e) {
        
        echo $e; //works gives me '100m Swim'

        $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
        $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 10;
      
        $query = $this->db->from('eresults')
                ->where('event', $e)
                ->order_by('event')
                ->limit($limit, $start)
                ->get();

        return $query->result_array();
    }
#17

[eluser]toopay[/eluser]
Working on it. Make sure you load the database at model contructor or autoload it. Read the user guide too. If it working on controller, then it should easy to move it to better place right? ;-)
#18

[eluser]debow[/eluser]
Yeah, the model is loaded. Its called correctly and is displaying $e on the echo from the model but the same query that returned the string from your example when placed in the controller doesn't work when in the model. Thanks for working on it, trying to find some reff's to this in the user guide as well.
#19

[eluser]debow[/eluser]
Just an FYI, I did get your test query to return again with the same results from the test.

This is ran in the controller.
var_dump($this->Results_model->ext_get_all('100m Swim'));

The model looks like your test function. I get this on the return.

100m Swim //This is from my 'echo $e'

//This is from your return $query->result_array();

array(1) { [0]=> array(14) { ["id"]=> string(3) "541" ["athlete_id"]=> string(3) "210" ["event"]=> string(9) "100m Swim" ["gender"]=> string(3) "men" ["result"]=> string(0) "" ["mins"]=> string(1) "1" ["secs"]=> string(2) "59" ["msecs"]=> string(3) "0.8" ["totalsecs"]=> string(5) "119.8" ["date"]=> string(4) "2011" ["eventrank"]=> string(0) "" ["eventscore"]=> string(0) "" ["eorder"]=> string(1) "1" ["name"]=> string(12) "Damon Powell" } }




Theme © iAndrew 2016 - Forum software by © MyBB