Yii Framework Forum: How To Display Database Values Into The View Page - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How To Display Database Values Into The View Page Rate Topic: -----

#1 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 04:20 AM

Hi, i need to display my db values in the view page. And My Database is...
CREATE TABLE IF NOT EXISTS `users_stats_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `loginId` int(11) NOT NULL,
  `height` float DEFAULT NULL,
  `weight` float DEFAULT NULL,
  `chest` float DEFAULT NULL,
  `waist` float DEFAULT NULL,
  `hips` float DEFAULT NULL,
  `biceps` float DEFAULT NULL,
  `bmi` varchar(50) DEFAULT NULL,
  `createrId` int(11) DEFAULT NULL,
  `CreatedDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updaterId` int(11) DEFAULT NULL,
  `updatedDate` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `userid` (`loginId`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

ANd my view page is like this......
<html>
	<head>
    	<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
     	<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<!-------------------------------------------------Script for onchange------------------------------------------------------------------>
     	<script type="text/javascript">
        	function myfunction(v){
             	alert(v);

                	$.ajax({
                        	url: '<?php echo Yii::app()->createAbsoluteUrl("usersStatsInfo/graph"); ?>',
                        	type: 'POST',
                    	//   async: false,
                    	data: 'ans='+v ,
                    	success: function(res)
                    	{

                        	alert(res);
                        	alert("inside success");

                    	}
                    	});
           	}
    	</script>
</head>
<body>
<table border="0">
	<tr>
		<td align="left" valign="middle" width="15%" class="fields">
                    	<select name="bodyStats" title="Select Stats" onchange="myfunction(this.value)">
                        	<option value="56">Weight</option>
                        	<option value="60">height</option>
                        	<option value="bmi">BMI</option>
                        	<option value="chest">Chest</option>
                        	<option value="waist">Waist</option>
                        	<option value="hips">Hips</option>
                        	<option value="biceps">Biceps</option>
                    	</select>
                    	</td>
		</tr></table>
</body>
</html>

And My controller is like this..........

public function actionMyGraph() {
      	$model = new UsersStatsInfo();
       	if(Yii::app()->request->isAjaxRequest) {
            	if(isset ($_POST['ans'])) {
                	$result = $_POST['ans'];
                	echo $result;
                	//$this->render('myGraph', array('model'=>$model, false, true));
            	}
        	} 
        	$this->render('myGraph',array('model'=>$model));
    	}


0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 04:56 AM

find the results in the view page

or

find the results in the controller action and pass the variable to view page

then display it!! what is the confusion?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 05:00 AM

I tried like that but i'm not getting .....
0

#4 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 05:03 AM

if your qn is ajax related, the make the changing part of the view file to a separate file and renderPartial the page, in the action
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 05:04 AM

where ajax calling?
is it a dropdown?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 05:07 AM

yes sir......... i'm calling ajax for dropdown
0

#7 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 05:12 AM

i dont know the structure of the ur view

i think
make this part as a single file,

then renderPartial it in the action, with the find values!!

        <option value="56">Weight</option>
                                <option value="60">height</option>
                                <option value="bmi">BMI</option>
                                <option value="chest">Chest</option>
                                <option value="waist">Waist</option>
                                <option value="hips">Hips</option>
                                <option value="biceps">Biceps</option>


that is the basic idea.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#8 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 05:19 AM

echo CHtml::dropDownList('ur-name','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('currentController/dynamiccities'), //url to call.

'update'=>'#div-id', //selector to update

))); 


<div id="div-id"></div>


in controller

find the values with post value if dropdown according to your use

then renderPartial the page, pass the result to the view file
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
1

#9 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 05:46 AM

Hi sir, based on select option i need to display the values. And i tried your way, i'm getting error like this.....

"Object of class UsersStatsInfo could not be converted to string"
0

#10 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:05 AM

View PostDevendra411, on 24 June 2013 - 05:46 AM, said:

Hi sir, based on select option i need to display the values. And i tried your way, i'm getting error like this.....

"Object of class UsersStatsInfo could not be converted to string"


where?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#11 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:09 AM

your dropdown code pls
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#12 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 06:13 AM

NOw i' getting Undefined index: height
echo CHtml::dropDownList('UsersStatsInfo','', array(1=>'height',2=>'weight',3=>'chest'),
        	array(
            	'ajax' => array(
            	'type'=>'POST', //request type
            	'url'=>CController::createUrl('usersStatsInfo/myGraph'), //url to call.

            	'update'=>'#td-id', //selector to update

        	)));
     	
      	$height = $_POST['height'];
      	$weight = $_POST['weight'];
      	$chest = $_POST['chest'];
      	
      	echo $height;
      	echo $weight;
      	echo $chest;

0

#13 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:16 AM

you will get the post value as $_POST['UsersStatsInfo']
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#14 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:17 AM

controller action code ?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#15 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:25 AM

View PostDevendra411, on 24 June 2013 - 06:24 AM, said:

Sir i dont know how to find the values with post value in controller action


what is your purpose? what you want to display in the view page?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#16 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:27 AM

if your required dropdown need these options

                                <option value="56">Weight</option>
                                <option value="60">height</option>
                                <option value="bmi">BMI</option>
                                <option value="chest">Chest</option>
                                <option value="waist">Waist</option>
                                <option value="hips">Hips</option>
                                <option value="biceps">Biceps</option>


then the post values are 56 or 60 or bmi or chest or..or.. etc

what you want to find with this dropdown?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#17 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 06:28 AM

Based on select option I need to display database value
0

#18 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 06:40 AM

View PostDevendra411, on 24 June 2013 - 06:28 AM, said:

Based on select option I need to display database value



so find it using findByAttributes() or something like that

what value? what is your expected output? what you want to show?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#19 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 24 June 2013 - 06:57 AM

If i select "height" in the dropdown the height value 50or something whatever in db that value i need to show in my view page. if i select weight, the weight value i need to show in my view page
0

#20 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 24 June 2013 - 07:00 AM

View PostDevendra411, on 24 June 2013 - 06:57 AM, said:

If i select "height" in the dropdown the height value 50or something whatever in db that value i need to show in my view page. if i select weight, the weight value i need to show in my view page



ok all weight values?/all height value?

so you have to find it in the action..

pls test with something echo in the action.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users