Skip to main content

[ask] gabungin $id dan $offset dalam parameter..

January 15, 2011 by arro

arro's picture

permisi semua..sy mau nanya lg nih...
gimana ya cara gabungin $id dan $offset?
itu malah errornya gni :
Message: Missing argument 2 for People::get_messages_people()
Message: Undefined variable: offset
kalau ga pake $id bisa jalan, tapi sy membutuhkan $id utuk memberi nilai di model...
apa ga bisa naruh id dan offset di parameter secara bersamaan ya?
mohon bantuannya ya?
terima kasih atas waktunya...

sy punya controller dengan function :

 function get_messages_people($id,$offset){ //di sini yg error
   $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);//di sini yg error
 }

sy punya model dengan function :

function get_messages_people($id,$offset=0){
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where('posts.receiper',$id);
		$this->db->limit(10,$offset);
		$query = $this->db->get();
		return $query->result();
	}

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

yawdah ganti aja yang $id tu

January 17, 2011 by myhariez, 19 hours 23 min ago
Comment: 7539

myhariez's picture

yawdah ganti aja yang $id tu dengan offset.
"Undefined variable: offset" kan karena variable $offset belum didefenisikan sebelumnya atau belum diset/diisi data seblumnya udah agan pake.
cb dikasih aja script:

if( !isset($offset) or $offset = '' ){
$offset = 0; //terserah agan bisa disi null, atau ''
} else {
$offset = $offset;
}
:D

tetep ga mau mas... apa ya

January 17, 2011 by arro, 17 hours 31 min ago
Comment: 7540

arro's picture

tetep ga mau mas...
apa ya problemnya?
bingung bgt mslh nie...

masih gak mau juga?? itu

January 17, 2011 by myhariez, 1 hour 50 min ago
Comment: 7541

myhariez's picture

masih gak mau juga??
itu parameter $id di get_messages_people($id,$offset) tu mo agan ambil dari mana? dari URL kah?

itu karna $id gak

January 16, 2011 by myhariez, 1 day 56 min ago
Comment: 7534

myhariez's picture

itu karna $id gak didefinisikan dolo gan

coba ja ditambaho sendiri

function get_messages_people($id,$offset){ //di sini yg error
 
if( !$id or $id == ''){
$id = 0; //didefaultkan jika parameter $id tidak diset
}
 
 
   $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);//di sini yg error
 }

kalo nggak ya yang dimodel tu ditaruh juga validasinya

function get_messages_people($id,$offset=0){
if( !$id ){
$id = 0;
} else {
$id = $id;
}
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where('posts.receiper',$id);
		$this->db->limit(10,$offset);
		$query = $this->db->get();
		return $query->result();
	}

moga bis angebantu gan :D

yg error offset-nya mas..kalo

January 16, 2011 by arro, 22 hours 44 min ago
Comment: 7535

arro's picture

yg error offset-nya mas..kalo mau definisiin dimana ya?
tetep aja erornya muncul gni mas :
Message: Undefined variable: offset

bingung neh mas...

Premium Drupal Themes by Adaptivethemes