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

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");

Related

Scrapy - Extract data from table

I am trying to fetch data from a table into separate fields of a CSV file.
The table in the website looks like this:
And (part of) the source of the webpage looks like this:
<div id="right">
<div id="rightwrap">
<h1>Krimpen aan den IJssel</h1>
<div class="tools">
print
terug
</div>
<h2 class="lijst">Krimpen aan den IJssel</h2>
<div class="dotted"> </div>
<div class="zoekres">
<h4>Aantal kindplaatsen</h4>
<div class="paratable">
<table cellpadding="0" cellspacing="0">
<tr>
<th> </th>
<th>2006</th>
<th>2008</th>
<th>2009</th>
<th>2010</th>
<th>2011</th>
</tr>
<tr>
<th>KDV</th>
<td>144</td>
<td>144</td>
<td>174</td>
<td>243</td>
<td>-</td>
</tr>
<tr>
<th>BSO</th>
<td>135</td>
<td>265</td>
<td>315</td>
<td>365</td>
<td>-</td>
</tr>
<tr>
<th>Totaal</th>
<td>279</td>
<td>409</td>
<td>489</td>
<td>608</td>
<td>-</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="brtotal"> </div>
</div>
I managed to retrieve the name of the place "Krimpen aan den IJssel" using this code:
def parse(self, response):
item = OrderedDict()
for col in self.cols:
item[col] = 'None'
item['Gemeente'] = response.css('h2.lijst::text').get('')
yield item
But I am unable to retrieve the values displayed in the table of this website. The standard approach for table using:
response.xpath('//*[#class="table paratable"]
doesn't seem to work or I am not experienced enough to set the parameters right.
Can anyone provide me with some lines of code that will bring the
values from this table into the following columns of my CSV-file
KDV_2006 KDV_2008 KDV_2009 KDV_2010 KDV_2011 BSO_2006 BSO_2008
BSO_2009 BSO_2010 BSO_2011
One possible way:
result = {}
years = response.xpath('//div[#class="paratable"]/table/tr[1]/th[position() > 1]/text()').getall()
for row in response.xpath('//div[#class="paratable"]/table/tr[position() > 1][position() < last()]'):
field_name = row.xpath('./th/text()').get()
values = row.xpath('./td/text()').getall()
for year, value in zip(years, values):
result[f'{field_name}_{year}'] = value

Php 7 error for a simple form getting Object of class mysqli could not be converted to int

The code gets error saying Object of class mysqli could not be converted to int. When i try to load the page i get this error,i checked other questions but it was not helpful
<?php
$conn = mysqli_connect("localhost", "root", "", "coinlion");
if ($conn == 0) {
echo "could not connect";
} else {
mysqli_select_db("coinlion");
echo "connected";
}
?>
<form method="post">
<style>
#newlink {
width: 600px
}
</style>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL:</td>
<td><input type="text" name="linkurl" value="" required></td>
</tr>
<tr>
<td> Link Description:</td>
<td><textarea name="linkdesc" cols="50" rows="5" required></textarea>
</td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
php code
<?php
if (isset($_POST['submit1'])) {
$linkurl = $_POST['linkurl'];
$linkdesc = $_POST['linkdesc'];
mysqli_query($conn, "insert into
test(linkurl,linkdesc)values('$_POST[linkurl]','$_POST[linkdesc]')");
echo "data inserted";
}
?>
Well the issue was with the line if($conn==0) ,This value was taken as an integer so the error occured and an Connection variable to Mysqli_select_db was missing , after fixing it , the code ran successfully

vue.js when sorting grid only values is updated, not HTML

I am new to Vue.js, and could really use som help on this one.
I am trying to put a class (success) on my table rows to give them background color depending on the value of a property (status) in each of the objects in Array (data), wich is working as intended using the v-bind:class.
The problem arises when i sort the table rows by clicking on the table headers. When this is done there is a mismatch between the colored rows and their content, as if only values of rows is updated and not the rows themselves.
Try it here : https://jsfiddle.net/Bayzter/cyv1o78s/
Does anyone know how to solve this, so colored rows again match up with the correct objects?
<script type="text/x-template" id="grid-template">
<table>
<thead>
<tr>
<th v-for="key in columns"
#click="sortBy(key)"
:class="{active: sortKey == key}">
{{key | capitalize}}
<span class="arrow"
:class="sortOrders[key] > 0 ? 'asc' : 'dsc'">
</span>
</th>
</tr>
</thead>
<tbody>
<tr v-for="
entry in data
| filterBy filterKey
| orderBy sortKey sortOrders[sortKey]" v-bind:class="{ 'success' : data[$index].status == 0}">
<td v-for="key in columns">
{{entry[key]}}
</td>
</tr>
</tbody>
</table>
</script>
<!-- demo root element -->
<div id="demo">
<form id="search">
Search <input name="query" v-model="searchQuery">
</form>
<demo-grid
:data="gridData"
:columns="gridColumns"
:filter-key="searchQuery">
</demo-grid>
</div>
Where you have
v-bind:class="{ 'success' : data[$index].status == 0}"
You want
v-bind:class="{ 'success' : entry.status == 0}"
$data[$index] is not going to refer to the current-order item, it's going to refer to the original-order item. entry is the current item.

How to click on the checbox from a list of checkboxes available inside a table using selenium

I have been trying to click on the one particular checkbox, but all the checkboxes have the same tags and parameters inside. Only the text which is the name of the check box is varying, but unfortunately couldn't get that also to be used. Kindly do help me with this.
Html code:
<tr class="ng-scope" ng-repeat="group in groupsList | orderBy:'groupName'">
<td class="col-xs-4 ng-binding">
<input class="ng-scope ng-pristine ng-valid" type="checkbox" checklist-value="group" ng-model="checked"/>
Checkbox1 name
<br/>
</td>
</tr>
<!-- end ngRepeat: group in groupsList | orderBy:'groupName' -->
<tr class="ng-scope" ng-repeat="group in groupsList | orderBy:'groupName'">
<td class="col-xs-4 ng-binding">
<input class="ng-scope ng-pristine ng-valid" type="checkbox" checklist-value="group" ng-model="checked"/>
Checkbox2 name
<br/>
</td>
</tr>
<!-- end ngRepeat: group in groupsList | orderBy:'groupName' -->
<tr class="ng-scope" ng-repeat="group in groupsList | orderBy:'groupName'">
<td class="col-xs-4 ng-binding">
<input class="ng-scope ng-pristine ng-valid" type="checkbox" checklist-value="group" ng-model="checked"/>
Checkbox3 name
<br/>
</td>
</tr>
<!-- end ngRepeat: group in groupsList | orderBy:'groupName' -->
<tr class="ng-scope" ng-repeat="group in groupsList | orderBy:'groupName'">
<td class="col-xs-4 ng-binding">
<input class="ng-scope ng-pristine ng-valid" type="checkbox" checklist-value="group" ng-model="checked"/>
Checkbox4 name
Answers would be very much helpful and appreciated.
The xpaths I have tried:
//table/tbody/tr/td/input/following-sibling::text()
this is highlighting all the texts i.e names of checkboxes
//table/tbody/tr/td/input/following-sibling::br/preceding::text()='Checkbox name'
//table/tbody/tr/td/input/text()\[preceding::br and contains(../text(),'Checkbox name')\][1]
You should try using following xPath to select checkbox which is based on visible text :-
//td[contains(., 'Checkbox1 name')]/input
As you mentioned in the question, your purpose is to click on the checkbox.
You can select the input tag with the exact text:
//input[.="Checkbox1 name"]
or if you think there could be some extra spaces or text around the text, then you can use contains function:
//input[contains(., "Checkbox1 name")]
Also you can select by index:
element(by.tagName('table')).all(by.tagName('input')).get(INDEX).click();
Check this - protractor allows to search byCssContaining text -
http://www.protractortest.org/#/api?view=ProtractorBy.prototype.cssContainingText
It might be better than xPath.
Here is for your question:
function clickCheckboxByName (name) {
var checkbox = element(by.cssContainingText("input[type='checkbox']", name));
checkbox.click();
}

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

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