Select Data Using User Id

hi i need get list of offer detail which user is insert using User_id this user id already save by session

i need show offer which user insert when he or she login their profile

CREATE TABLE IF NOT EXISTS offer_detail (

id int(60) NOT NULL AUTO_INCREMENT,

company_id int(60) NOT NULL,

offertype_id int(60) NOT NULL,

category_id int(60) NOT NULL,

offer_title varchar(150) NOT NULL,

offer_description text NOT NULL,

image varchar(150) NOT NULL,

coupon_id varchar(60) NOT NULL,

price text NOT NULL,

unit_id varchar(60) NOT NULL,

price_now varchar(60) NOT NULL,

from varchar(80) NOT NULL,

to varchar(80) NOT NULL,

[color="#FF0000"][size="4"]user_id int(10) NOT NULL,[/size][/color]

created varchar(11) NOT NULL,

modified varchar(10) NOT NULL,

Active varchar(100) NOT NULL,

PRIMARY KEY (id),

KEY company_id (company_id,category_id,coupon_id,unit_id),

KEY category_id (category_id,coupon_id,unit_id),

KEY coupon_id (coupon_id),

KEY unit_id (unit_id),

KEY offertype_id (offertype_id),

KEY user_id (user_id,Active)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

thank you …

try this…


$data=Offerdetail::model()->find("user_id = Yii::app()->user->id");

if you are showing using CGridView then in search() method you have to add condition

$criteria->addCondition($this->user_id=Yii::app()->user->id);

hope i may help you :)

add this on admin grid view…





             array(

                'name'=>'user_id',

                'value'=>'GxHtml::valueEx($data->user,\'fullname\')',

                'filter'=>GxHtml::listDataEx(Offerdetail::model()->findAll('userr_id=\'Yii::app()->user->id\''), 'id', 'fullname'),

                ),

and filter search functionality working put a kalpit code on model search function

i want to add this in my button screen shot here

<?php echo CHtml::submitButton(‘See my Offer’, array(‘submit’ => array(’…’), ‘class’ => ‘input button primary’)); ?>

how prepare CURD for this ?

Hi,

you can use the CController method…

(please visit : http://www.yiiframework.com/doc/api/1.1/CController)

for example…i want to create the all registred data and display the record on CRUD

My model name is User.php

My Controller Name : UserConteroller.php

My view : user/admin.php

so i want to display the record


<a  href="<?php echo CController::createUrl('User/index'); ?>">User List</a>

in UserConteroller.php create the actionindex and render the data


public function actionIndex(){

  $this->render('/user/admin');

}

i hope it’s may be helpful…

can i add User_id instand id in my _view.php for this

<?php echo CHtml::submitButton(‘See Offer’, array(‘submit’ => array(‘view’, ‘id’=>$data->id)); ?>

i mean like this

<?php echo CHtml::submitButton(‘See Offer’, array(‘submit’ => array(‘view’, ‘user_id’=>$data->user_id)); ?>

can i add User_id instand id in my _view.php for this

<?php echo CHtml::submitButton(‘See Offer’, array(‘submit’ => array(‘view’, ‘id’=>$data->id)); ?>

i mean like this

<?php echo CHtml::submitButton(‘See Offer’, array(‘submit’ => array(‘view’, ‘user_id’=>$data->user_id)); ?>

Chtml::submitButton you can pass any varible to the controller…

but make sure you are passing right value only…

my suggestion is that instead of passing $data->user_id you pass Yii::app()->user->id it may be better. because it always refer currently logged in user id.

$data->user_id sometime may cause problem for you…