Вопрос

i have an array that am calling from the database using kohana 3.3 i have gotten the data to the view and i can get it with print_r($variable). i want to create a movenext, movefirst,moveprevious and movelast buttons based on the data that is in the array.

my model looks like this

    public function get_customer_list(){    
$cust_list= DB::select('*')->from('customers')
                    ->order_by('id','ASC') 
                    ->execute()
                    ->as_array();
//print_r($cust_list);                  
return $cust_list;

my controller looks like this

 $id=@$_POST["id"];
    //echo $id;
$amend  = Model::factory('amendments')->get_customer_list(@$d);
$this->page_title = 'amending';
$this->content = View::factory('forms/amendment_next');
//$this->rightwidget =view::factory('rightwidget');
$this->amend = $amend;
$this->next = $id;

my view looks like this

foreach ($amend[0] as $key=>$value){
        echo '<p><span>'.$key.'</span><input id="'.$next.'" class="contact" type="text" name="'.$key.'"value="'.$value.'" /></p>';          
                    }
<a href="#" id="getnext">Next Record</a>
<a href="javascript:void(0);" id="previous">Previous Record</a><button >Next Record</button><button>Last Record</button>

i dont mind using a link or a button

please assist am stack here and my brain is locked.

Это было полезно?

Решение 3

I used your example to project myself over the problem. and now it stands solved here is the The Controller looks like this now

   $id=@$_GET["id"];
$amend  = Model::factory('amendments')->get_customer_list(@$d);
$this->page_title = 'I&M CRB Online App amending';
$this->content = View::factory('forms/amendments');
//$this->rightwidget =view::factory('rightwidget');
$this->amend = $amend;
$this->next = $id;

the view looks something like this

 <?php 
if (!$next){
$next = "0";}

$nextid = $next+"1";
$previd=$next-"1";
?>
<a href="<?php echo HTTP_PATH; ?>/amend/getnext/?id=<? echo "0"; ?>">First Record </a> |
<a href="<?php echo HTTP_PATH; ?>/amend/getnext/?id=<? echo $previd;?>">Previous Record</a> |
<a href="<?php echo HTTP_PATH; ?>/amend/getnext/?id=<? echo $nextid;?>">move next</a> |
<a href="<?php echo HTTP_PATH; ?>/amend/last">Last Record</a> 
<?php
        foreach (@$amend[@$next] as $key=>$value){
        echo "<p><span>".$key."</span><input class='contact' type='text' name='".$key."'value='".$value."' /></p>"; 
}   


?>

and for the last record i had to use a different model function

public function get_last_customer(){    
    $last_customer= DB::select()->from('customers')
                        ->order_by('id','DESC')
                        ->limit(1)
                        ->execute()
                        ->as_array();
    return $last_customer;  

Thank you all for the support and the answers you provided me with.

Другие советы

Try this in your view, just a some javascript code is needed (i have used jQuery)

---next() Example---

$(document).ready(function (){
    var customers = <?php echo json_encode($amend) ?>;
    var count = 0;

    function nextItem(){
        if(count >= customers.length )return;
        console.log("customer:",customers[count]['id'],customers[count]['name']);
        count =++count;
    }
})

Your controller should look like this:

$id=@$_POST["id"];
//echo $id;
$amend  = Model::factory('amendments')->get_customer_list(@$d);
$this->page_title = 'amending';
$inputArray = array('amend'=>$amend, 'id'=>$id);

$this->content = View::factory('forms/amendment_next',$inputArray);
//$this->rightwidget =view::factory('rightwidget');

You either have to pass the variables you want to use in your view directly to the factory as an associative array or you have to make them globally availible to the factory.

Your view should look like this:

<? 
foreach ($amend[0] as $key=>$value){
        echo '<p><span>'.$key.'</span><input id="'.$next.'" class="contact" type="text" name="'.$key.'"value="'.$value.'" /></p>';          
}
?>
<a href="something.php?id=<? echo $id;?>" id="getnext">Next Record</a>
<a href="javascript:void(0);" id="previous">Previous Record</a><button >Next Record</button><button>Last Record</button>

after passing the $inputArray to the factory the vairable $amend will be filled with $inputArray['amend'] and $id will be filled with $inputArray['id']

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top