how to get name based on id from DB table in yii framework - yii

i am developing web application by using yii framework, i have one table called "userprofile" in my database. i have tried to export userprofile data to excel file, everything is working fine this is my userprofile table fields
user profile table
id username password studentname classid parentname email
1. xxxxx asdf yyyyy 2 pqrs xy#gmail.com
classname table
classid classname
1. xxxxx
2. yyyyy
3. zzzzz
In my controller i have one function called actionExcelexport() and it has
$content = $this->renderPartial("excel",array("model"=>Puserprofile::model()->findAll()),true);
In above line i am calling one excel file called excel and this is my excel.php
<table>
<tr>
<td style="background-color: #555;color:#fff">User Name</td>
<td style="background-color: #555;color:#fff">Student Name</td>
<td style="background-color: #555;color:#fff">ClassID</td>
<td style="background-color: #555;color:#fff">Parent Name</td>
<td style="background-color: #555;color:#fff">Email</td>
</tr>
<?php foreach($model as $data):?>
<tr>
<td> <?php echo $data->username ?> </td>
<td> <?php echo $data->studentname ?> </td>
<td> <?php echo $data->classid ?> </td>
<td> <?php echo $data->parentname ?> </td>
<td> <?php echo $data->email ?> </td>
</tr>
<?php endforeach; ?>
</table>
my reqirement:-
In my excel file i want to get classname instead of classid for example if my classs id is '2', classname 'yyyy' should get in excel file how to retrive classname based on classid could you please help me

i got solution for my problem
In my excel.php, instead of this line
classid ?>
i changed
class->classname?>
class->classname = my userprofile model has relation function and it has some relation because i am using foreign key for my table so i am taking this 'class' from my model and this is ('classname') my database field name

Related

skrape.it process rows of a table by itself

I am new to the skrape.it library and try to extract content of a table.
Is there a way to process every table by it self, so I get a List with all texts of a row in a List with all rows? e.g.: List<List>
My current approach is to get all texts from every td and count all tr and then process these two lists by calculating the index of the required text.
One row looks like this:
<tr role="row">
<td class="grad" style="background:#067A25; width:50px">
<div class="grad_outer">
<span>4c</span>
</div>
</td>
<td class="name">
King Louie
</td>
<td>
Dave
</td>
<td>
11.03.2022
</td>
<td>
12
</td>
<td>
64.2
</td>
</tr>
I also need to extract the background css attribute of each first td tag. How can I do this?

listview html display in Yii1.1

I am not getting any output html from below code
$this->widget('zii.widgets.CListView', array(
'id'=>'skills-grid',
'itemView'=>'scheduled_skills',
'dataProvider'=>$model->search(),
));
Is there any demo available for listview example in yii1.1?
Please share the links for listview example in yii1.1
You can used this code for ClistView in Yii1.1
Clistview File for ex : index.php
$this->widget('zii.widgets.CListView', array(
'id'=>'skills-grid',
'itemView'=>'_scheduled_skills', // Your View file
'dataProvider'=>$model->search(),
));
ClistView View file for ex : _scheduled_skills.php
<table class="table">
<tbody>
<tr>
<td><span class="title"><strong> First Name</strong> </span></td>
<td><span class="title"><?php echo $data->first_name;?></td>
</tr>
<tr>
<td><span class="title"><strong>Last Name</strong> </span></td>
<td><span class="title"><?php echo $data->last_name;?></td>
</tr>
</tbody>
</table>
You can direct access $data object in ClistView File.
you can refere this Link Yii1 ClistView

SQL query for dynamic table column selection from checkbox in codeigniter?

I am trying to retrieve the columns from the database based on checkbox selection in codeigniter. But I have no idea how to do it?
For example there's a columns in a database table Member:
| ID | Name | Gender | Status |
---------------------------------------
| 1 | Anne | F | Member |
| 2 | Brown | M | Member |
| 3 | Carl | M | Member |
Then there's checkboxes in the data.php view to select which column to display
<?php echo form_open(data/getData);?>
<label class="col-md-4" for="parameter">Parameter</label>
<div class="col-md-6">
<input type="checkbox" id="parameter" value="name"> Name <br>
<input type="checkbox" id="parameter" value="gender"> Gender <br>
<input type="checkbox" id="parameter" value="status"> status <br>
</div>
<input type="submit" class="btn btn-md btn-info" value="Process" />
<?php echo form_close();?>
<div class="well">
<table class="table table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr class="info">
<th>ID</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($query as $d): ?>
<tr>
<td><?php echo $d['ID'];?></td>
<td><?php echo $d[''];?></td>
<td><?php echo $d[''];?></td>
<td><?php echo $d[''];?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>
How to dynamically make the column name retrieved from the checkbox?
Data_model.php:
function getData(){
//I don't know how to get the dynamic column select from the view to the select query
$this->db->select(?);
$this->db->from('member');
$query = $this->db->get();
return $query->result();
}
Anyone help me with this please?
Try this simple approach , make a POST/GET with a name attribute param[] an array
<input type="checkbox" id="parameter" name="param[]" value="name"> Name <br>
<input type="checkbox" id="parameter" name="param[]" value="gender"> Gender <br>
<input type="checkbox" id="parameter" name="param[]" value="status"> status <br>
in PHP (assuming post value)
$param = $this->input->post('param');
//if no param get all columns
if(empty($param)){
$param = '*';
}else{
//if array value is more than 1 use implode else just take the 1st array
$param = (count($param) > 1 ) ? implode(',', $param) : $param[0]; //make a single string and concatenate them with ,
}
example output: name,status
then use $param in your model like this $this->db->select("$param");

Simple Pie "set_item_limit" doesn't

I'm struggling to get set_item_limit to work. The feed comes in fine, but just renders every post. Here's the code I'm using:
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('php/autoloader.php');
// process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process. http://simplepie.org/blog/feed/
$feed->set_feed_url('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Tweet_Yourself');
// Run SimplePie.
$feed->set_item_limit(5);
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
And here's the HTMLy bit:
<?php
//loop through all of the items in the feed, and $item represents the current item in the loop.
foreach ($feed->get_items() as $item): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="left"><img src="sitewise/Tweet_Yourself_avatar.gif" alt="TweetYourself Twitter Feed" /></td>
<td>
<div class="item">
<h3><i><?php echo $item->get_title(); ?></i></h3>
<?php echo $item->get_description(); ?>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
<hr />
</div>
</td>
</tr>
</table>
<?php endforeach; ?>
The table isn't the issue!
Any ideas?
The issue is
$feed->set_item_limit(5);
Is for merging feeds and not for a single feed.... you need to
change
foreach ($feed->get_items() as $item): ?>
to
foreach ($feed->get_items(0, 5) as $item): ?>
This would limit it to 5 items
SimplePIE Get_ITEMS

cakephp sql log is correct, not returning data

I'm creating a simple view function, after checking my sql log its correct, However my view is not printing the information.
SELECT `AccountsUser`.`id`, `AccountsUser`.`account_id`
FROM `pra`.`accounts_users` AS `AccountsUser`
WHERE `user_id` = 14
SELECT `Template`.`id`, `Template`.`name`, `Template`.`description`,
`Template`.`account_id`
FROM `pra`.`templates` AS `Template`
WHERE `Template`.`account_id` = (10)
The account_id=10 but it isn't printing out the templates related to the account.id
function view(){
$this->set('title_for_layout', 'View Templates');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
$this->Template->unbindModel(array('belongsTo'=>array('Account')));
$templates = $this->Auth->user('name');
$accounts=$this->User->AccountsUser->find('list', array('fields'=>array('id', 'account_id'),'conditions' => array('user_id' => $this->Auth->user('id'))));
$templates=$this->Template->find('all', array('conditions' => array('Template.account_id' => $accounts)));
$this->set('template', $templates);
$this->set('account'. $accounts);}
Here is the view
<table width="100%" border="1">
<table width="100%" border="1">
<tr>
<th>Template Name</th>
<th>Template Description</th>
</tr>
<?php foreach($template as $templates): ?>
<tr>
<td align='center'><?php echo $templates['templates']['id']; ?> </td>
<td align='center'><?php echo $templates['templates']['name']; ?> </td>
</tr>
<?php endforeach; ?>
</table>
id like it to print a list of templates related to the account.id
You should try the following:
<table width="100%" border="1">
<tr>
<th>Template Name</th>
<th>Template Description</th>
</tr>
<?php if(!empty($template))
{
foreach($template as $templates)
{?>
<tr>
<td align='center'><?php echo $templates['Template']['id']; ?> </td>
<td align='center'><?php echo $templates['Template']['name']; ?> </td>
</tr>
<?php
}// end of foreach
}
else
{?>
<tr> <td>No Templates Found.</td></tr>
<?php
}?>
</table>