I have an error in try concatenate in a query in my controller:
$asignaciones = DB::table('asignaciones')
->join('dueños','asignaciones.dueno_id','=','dueños.id')
->join('choferes','asignaciones.chofer_id','=','choferes.id')
->select('asignaciones.*', 'dueños.nombre as dueño_nombre',
'dueños.apellido as dueño_apellido','dueños.ci as dueño_ci','dueños.celular as dueño_celular',
'choferes.nombre '+'choferes.apellido as chofer_fullName',
'choferes.ci as chofer_ci','choferes.celular as chofer_celular')
->get();
The error message is:
"A non-numeric value encountered"
My questions is, how can I concatenate or unite two columns in one
in the line, choferes.nombre '+' choferes.apellido as chofer_fullName?
Try using DB::raw() like this:
$asignaciones = DB::table('asignaciones')
->join('dueños','asignaciones.dueno_id','=','dueños.id')
->join('choferes','asignaciones.chofer_id','=','choferes.id')
->select('asignaciones.*', 'dueños.nombre as dueño_nombre',
'dueños.apellido as dueño_apellido','dueños.ci as dueño_ci',
'dueños.celular as dueño_celular',
DB::raw('CONCAT(choferes.nombre, choferes.apellido) AS chofer_fullName'),
'choferes.ci as chofer_ci','choferes.celular as chofer_celular')
->get();
Related
When I add SUM in Codeigniter SELECT, it returns only one row. But when I remove it, it returns all of the possible matching entries.
$this->db->where('posts.status',1)
->select('posts.title')
->select('posts.description')
->select('posts.posted_by')
->select('posts.posted_on')
->select('posts.category')
->from('posts')
->join('categories','posts.category=categories.id','LEFT')
->select('categories.title as cat_title')
->join('users','users.id=posts.posted_by','LEFT')
->select('users.username')
->select('users.first_name')
->select('users.last_name')
// this section is causing to return only one entry/row,
// when I remove/comment this section, it brings the desired results
->join('votes','votes.post_id=posts.id',"LEFT")
->select('SUM(upvote) as upvote_count')
->select('SUM(downvote) as downvote_count')
->get()
->result_object();
Try to add:
->group_by('posts.id')
After
->select('SUM(downvote) as downvote_count')
So now query will be:
$this->db->where('posts.status',1)
->select('posts.title')
->select('posts.description')
->select('posts.posted_by')
->select('posts.posted_on')
->select('posts.category')
->from('posts')
->join('categories','posts.category=categories.id','LEFT')
->select('categories.title as cat_title')
->join('users','users.id=posts.posted_by','LEFT')
->select('users.username')
->select('users.first_name')
->select('users.last_name')
// this section is causing to return only one entry/row,
// when I remove/comment this section, it brings the desired results
->join('votes','votes.post_id=posts.id',"LEFT")
->select('SUM(upvote) as upvote_count')
->select('SUM(downvote) as downvote_count')
->group_by('posts.id')
->get()
->result_object();
I know this question was already asked, but after trying most of the accepted answer none of them seems to work with my simple task...
I have a csv file as follow:
Date,Median
2000-01-31,9
2000-02-28,8
2000-03-31,7
2000-04-30,6
2000-05-31,5
2000-06-30,4
2000-07-31,3
2000-08-31,2
2000-09-30,1
2000-10-31,0
2000-11-30,11
2000-12-31,12
and then an array:
[0.1829 0.171349 0.162461 0.152306 0.14122 0.137749 0.138802 0.150315
0.156784 0.168297 0.180634 0.187241]
I wish to append this array as a third column to the csv file to get the following output:
Date,Median,Median2
2000-01-31,9,0.1829
2000-02-28,8,0.171349
2000-03-31,7,0.162461
2000-04-30,6,0.152306
2000-05-31,5,0.14122
2000-06-30,4,0.137749
2000-07-31,3,0.138802
2000-08-31,2,0.150315
2000-09-30,1,0.156784
2000-10-31,0,0.168297
2000-11-30,11,0.180634
2000-12-31,12,0.187241
I tried most of the answer related to this kind of question but I did not succeed to make them work..here is the last code I tried, using pandas that looks easier but it does not work:
data=pd.read_csv("data_1.csv",sep=',')
array_transpose = array.reshape((-1, 1)) #in order to transpose the array
data['Median2'] = data[array_transpose]
data.to_csv('output.csv')
which produce the following error:
KeyError: '[0.1829 0.171349 0.162461 0.152306 0.14122 0.137749 0.138802 0.150315\n 0.156784 0.168297 0.180634 0.187241] not in index'
How to append this array to my csv file?
You may not need reshape
data=pd.read_csv("data_1.csv",sep=',')
data['Median2'] = array
data.to_csv('output.csv')
Currently I am getting values like below
by using below formula in infopath.
eval(eval(Delegate, 'concat(., "; ")'), "..")
Result:-
i:0#.w|manol\sp_testuser2; i:0#.w|manol\sp_testuser1; i:0#.w|manol\kaeel;
We need to remove the " i:0#.w|manol\ " character from the result.
Like :-
sp_testuser2;sp_testuser1;kaeel
I tried with substring inside eval function but it showing error in formula.
Ex:-
eval(eval(substring(Delegate, 17), 'concat(., "; ")'), "..")
I had a similar issue. You can nest another eval. So it would be:
eval(eval(eval(Delegate, 'substring(.,17)'), 'concat(.,";")'),"..")
I'm compiling a lot of JSON data over API and getting an error: "ValueError: No JSON object could be decoded" I have bolded the line that generates the error.
Most perplexing is that it successfully enters the first dictionary entry, but I get the error when it repeates the for loop.
The problematic cell of code looks like this. 'genkey' and 'conkey' are dictionaries with about 50 keys, each one has a five or six digit number as its value.
gdata={}
cdata={}
for site in genkeys:
print genkeys[site]
gpayload = {'data_key_id': gdatakey, 'range_start': rangestart, 'range_end': rangeend,'period':'hour', 'token':'5b'}
gr = requests.get("http://appl.d.com/dta/raw.json?",params=gpayload)
print gr
print genkeys[site]
**gdata[gdatakey]=gr.json()**
if site in conkeys.keys():
cdatakey=conkeys[site]
cpayload = {'data_key_id': cdatakey, 'range_start': rangestart, 'range_end': rangeend,'period':'hour', 'token':'5b'}
cr = requests.get("http://appl.d.com/dta/raw.json?",params=cpayload)
cdata[cdatakey]=cr.json()
print gdata
print cdata
There was a null entry in the json code. That's what threw the error.
Here is my selection code from db:
$q = $this->db->like('Autor1' or 'Autor2' or 'Autor3' or 'Autor4', $vyraz)
->where('stav', 1)
->order_by('id', 'desc')
->limit($limit)
->offset($offset)
->get('knihy');
return $q->result();
Where $vyraz = "Zuzana Šidlíková";
And the error is:
Nastala chyba databázy
Error Number: 1054
Unknown column '1' in 'where clause'
SELECT * FROM (\knihy`) WHERE `stav` = 1 AND `1` LIKE '%Zuzana Ĺ idlĂková%' ORDER BY `id` desc LIMIT 9
Filename: C:\wamp\www\artbooks\system\database\DB_driver.php
Line Number: 330
Can you help me solve this problem?
Your syntax is wrong for what you're trying to do, but still technically valid, because this:
'Autor1' or 'Autor2' or 'Autor3' or 'Autor4'
...is actually a valid PHP expression which evaluates to TRUE (because all non-empty strings are "truthy"), which when cast to a string or echoed comes out as 1, so the DB class is looking to match on a column called "1".
Example:
function like($arg1, $arg2)
{
return "WHERE $arg1 LIKE '%$arg2%'";
}
$vyraz = 'Zuzana Šidlíková';
echo like('Autor1' or 'Autor2' or 'Autor3' or 'Autor4', $vyraz);
// Output: WHERE 1 LIKE '%Zuzana Šidlíková%'
Anyways, here's what you need:
$q = $this->db
->like('Autor1', $vyraz)
->or_like('Autor2', $vyraz)
->or_like('Autor3', $vyraz)
->or_like('Autor4', $vyraz)
->where('stav', 1)
->order_by('id', 'desc')
->limit($limit)
->offset($offset)
->get('knihy');