I am doing server side processing of datatables and I want to show extra col merged within a col, for eg. my table looks like:
id
name
age
price
Its all working fine, but I want to display another col in the price col which I am not able to get
For example: I want it to show like
id
name
age
price cur_code
I am trying the following
array(
'db' => 'serv_price',
'dt' => 8,
'formatter' => function( $d, $row ) {
return $d . " " . $row["serv_cur_code"];
}
),
but its not displaying it, how to get cur_code extra field ?
Thanks in Advance.
Related
I want to select id from moodle database where name is equal to some variable.I am trying this statement but so far its not working.
$questionname= $DB->get_record_sql('SELECT id
FROM {question} WHERE name = ?', array($name));
$questionid = $DB->get_field('question', 'id', array('name' => $name));
https://docs.moodle.org/dev/Data_manipulation_API#Getting_a_particular_field_value_from_one_record
I have the following issue with jenssegers query builder (I'm a new user):
print_r(DB::table($tablename)->where('_id',$_id)->select($table_structure_record['field'])->get());
returns me more than one column, despite only one column is specified in the select statement:
Array ( [0] => Array ( [_id] => MongoDB\BSON\ObjectID Object ( [oid] => 5780b81d93f7fb0e00d0f252 ) [collection] => structure ) )
My expected result would be only ([collection] => structure) , I don't understand why i also get "[_id] => MongoDB\BSON\ObjectID Object ( [oid] => 5780b81d93f7fb0e00d0f252 )"
Can someone help me ? Despite many searches, it seems select statement is supposed to return ONLY the columns specified, not any other !
MongoDb always returns the _id field unless you specifically set it not to while making the request(MongoDb Limit Fields to Return from Query Documentation).
You can try using project instead.Then it will be something like this:
DB::table($tablename)->where('_id',$_id)->project([$table_structure_record['field'] => 1, "_id" => 0])->get());
i'm not good with sql, i'm making a CListView for all records with a selected id in column to be displayed on the page.. just for practice, i wanted to add a dropdown that will select another kind of sort (id DESC is already there).
i have a table with columns: id, Name, Project_id, User_id, Assigned, etc...
for now this is my code:
public function actionView($id)
{
$model = $this->loadModel($id);
$criteria = new CDbCriteria(array(
'order'=>'id desc',
'condition'=>'Project_id='.$id
));
$dataProvider = new CActiveDataProvider('Task', array(
'criteria'=>$criteria
));
$this->layout = 'column2';
$this->render('view', array('model'=>$model, 'dataProvider'=>$dataProvider));
}
i'm selecting all records that has the requested project_id, so what i'm trying to do, which i have no clue how to do, is to add another criteria selection on the column "Assigned" the problem is, some of this records has more than 1 single assigned and its being saved as "1,2,5,6". so if i add another selection with assigned 1, it will just show me thoses records that have in assigned "1" and not thoses that have "1,3,5,6".. i was thinking on make a search on string but i dont know how it works on sql (Because i dont know SQL that much)
Try this -
$criteria = new CDbCriteria(array(
'order'=>'id desc',
'condition'=>'Project_id='.$id.' AND find_in_set($assigned, Project_id)'
));
But here $assigned can have only single value i.e. $assigned = 1 or $assigned = 2.
If $assigned = "1,2" where 1,2 itself will be considered as single value and so result will be returned only if the pattern is 1,2.. in the table and not 2,1,...
I hope it gives some idea.
found my solution.. seems like im using SQLite and SQLite does not support find_in_set(), instead. i would have to use (',' || Assigned || ',') LIKE '%,1,%'. like this..
$criteria = new CDbCriteria(array(
'order'=>'id desc',
'condition'=>'Project_id='.$id.' AND ("," || Assigned || ",") LIKE "%,5,%"'
));
I am trying to validate null values in a column and i have to update another column based on this validation. My request is,
Say i have Column 'Type' , if column 'Type' has some value in DB means i have to display tick mark in "Valid" column in CGridView. (Valid column is psuedo column)
Column 'Type' has null values means i have to display untick mark in "valid" column.
Please provide any idea over this.
Add New Column in Gridview with
array('name' => 'Status',
'value' => '!empty($data->type) ? "<img />" : "<img tag/>"',
'type' => 'raw'),
you can put your image tag with src in this.
I have a table named accessories_other in my database. In the table, I have column :
1) Item
2)Available
This is the illustration on how the data in the respective column.
Item
Mouse
Keyboard
Cable
Available
4
6
3
The thing is, I would like to select Item = 'Mouse' together with column 'Available'=4. If the available mouse is less than 5, it will send me an email for the next step. But I stuck until this stage.
This is SQL statement that I create, and it count each row for 'Available' column, and send the email if the row of Available column is less than 5, which is not I want.
$sql ="SELECT Item, Available FROM accessories_other WHERE Item ='Mouse'
AND Available <5";
How do I do so that it can retrieve mouse which is the availability less than 5.
This is just to show how it could be done . You should be using MySQLi
or PDO . Also if in Production environment , you should not be
displaying MySQL errors to the user .
You could do it either way :
// SQL to find Available value for Item Mouse
$sql = "SELECT Item, Available FROM accessories_other
WHERE Item = 'Mouse'";
$result = mysql_query( $sql ) or die( 'Query failed.'.mysql_error() );
$row = mysql_fetch_array( $result ) ;
if( mysql_num_rows( $result ) > 0 )
{
echo $row['Item'] ,': ' ,$row['Available'];
if( $row['Available'] < 5 )
{
// Code to send email
}
else
{
// Code to what ever you would like to do here
}
}
or
// SQL to find Available value for Item Mouse if it is less than 5
$sql = "SELECT Item, Available FROM accessories_other
WHERE Item = 'Mouse' AND Available < 5";
$result = mysql_query( $sql ) or die( 'Query failed.'.mysql_error() );
if( mysql_num_rows( $result ) > 0 )
{
// Code to what ever you would like to do here
}
else
{
echo $row['Item'] ,': ' ,$row['Available'];
// Code to send email
}
I think your query will not show results of mouse which is lesser than 5..
I suggest you try:
$sql ="SELECT Item, Available FROM accessories_other WHERE Item ='Mouse';
and then, try to implement your code in another language..
if I'm not mistaken, you're using php..
your query should return exactly one row if you have data in table "accessories" as shown here. unless you have duplicates like multiple rows rows with Item = 'Mouse' and same or different value which is also less than 5 then only query will return multiple results.
also just notice that in the explanation you use the table "accessories" but in sample query you have used table "accessories_other". make sure you are working against the right table.