When I click the save button on the input form, it will run the create method,
And trying to get the data in the database, but it does not work.
Error result, like this:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'E 0001) AS labels FROM buku WHERE id_judul = '1'' at line 1
SELECT IFNULL(MAX(label_buku), 500 Kin E 0001) AS labels FROM buku
WHERE id_judul = '1'
Filename: models/Buku_model.php
Line Number: 33
Model :
$label = $judul->klasifikasi.' '.substr($judul->penulis,0,3).' '.substr($judul->judul_buku,0,1).' '.'0001';//500 Kin E 0001
$id_judul = $input->id_judul; //1
$label_buku = $this->db->select("IFNULL(MAX(label_buku),$label) AS labels", false)
->where('id_judul',$id_judul)
->get($this->table)->row();//error
Please help me...
500 Kin E 0001 needs to be quoted:
SELECT
IFNULL(MAX(label_buku), "500 Kin E 0001") AS labels
FROM buku
WHERE id_judul = '1'
So in your CodeIgniter query:
$label_buku = $this->db->select("IFNULL(MAX(label_buku),\"$label\") AS labels", false)
->where('id_judul',$id_judul)
->get($this->table)->row();
Related
I'm using codeigniter, and I have a list of numbers (e.g. ['1', '2', '12', '42']) on a column (tags_json) of a table names submit, and I want to check if the number (e.g. '2') is in tags_json, in order to show the data the row's content.
The code I've tried is:
$this->db->select('*', FALSE);
$this->db->where("JSON_CONTAINS(tags_json,'[2]'");
$Query = $this->db->get('submit');
echo $Query->num_rows();
Result is:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3
SELECT * FROM submit WHERE JSON_CONTAINS(tags_json,'[2]' IS NULL
Filename: controllers/Home.php
Line Number: 281
How is it in CI's?
I've found a solution to your problem. use this code...
$this->db->select('*');
$this->db->where("JSON_CONTAINS(tags_json, JSON_ARRAY('2'))");
$Query = $this->db->get('submit');
echo $Query->num_rows();
it will output 1 and 0 if nothing's found.
if it will give you this error
Invalid JSON text in argument 1 to function json_contains: "Invalid value." at position 1.
SELECT * FROM submit WHERE JSON_CONTAINS(tags_json, JSON_ARRAY('2'))
it is because your json array is invalid so make sure your to have this format
["1", "2", "12", "42"]
or you just can have like this [1, 2, 12, 42] then call JSON_ARRAY(2)
hope that helps.
Since your server does not support the JSON family of functions JSON_CONTAINS you can try a good old LIKE statement
$this->db->where('tags_json LIKE "%\'2\'%"');
I am trying to display the total price in jtable using format concat & number format, like:
Rp 1.000.000
but i got an error
<div id="container">
<h1>A Database Error Occurred</h1>
<p>Error Number: 1064</p><p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as JUMLAH
FROM (`retribusi`)' at line 1</p><p>SELECT `ID_KATEGORI_RETRIBUSI`, `NAMA_KATEGORI_RETRIBUSI`, `TANGGAL`, CONCAT('Rp ', FORMAT(JUMLAH, `0))` as JUMLAH
FROM (`retribusi`)</p><p>Filename: C:\xampp\htdocs\swat1\system\database\DB_driver.php</p><p>Line Number: 330</p> </div>
i make query in model like this:
function get_all_retribusi()
{
$this->db->select("ID_KATEGORI_RETRIBUSI, NAMA_KATEGORI_RETRIBUSI, TANGGAL,CONCAT('$', FORMAT(JUMLAH, 2)) as JUMLAH");
return $this->db->get("retribusi");
}
but, when i try using SQL Query PHPmyadmin i get the data
like:
anyone can help me?
SELECT `ID_KATEGORI_RETRIBUSI`, `NAMA_KATEGORI_RETRIBUSI`, `TANGGAL`,
CONCAT('Rp ', FORMAT(JUMLAH, `0))` as JUMLAH
has a stray backtick ('`')
I think you want this instead:
SELECT `ID_KATEGORI_RETRIBUSI`, `NAMA_KATEGORI_RETRIBUSI`, `TANGGAL`,
CONCAT('Rp ', FORMAT(JUMLAH, `0)) as JUMLAH
Turns out there is a codeingiter setting for this:
$this->db->_protect_identifiers=false;
how i can select items between two values in codeigniter?
my table:
precocib
R$ 21.900,00
25.490,00
R$ 69.990,00
R$ 32.490,00
20.500,00
and my code to select this values is like this:
$this->db->where("precocib BETWEEN $faixaDe AND $faixaAte");
but visitors of my website can put value like this 10.000 or 10 or 10,000.00 and
when they put values like this i got an error
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00 AND 17490,00' at line 3
SELECT `default_produtos`.* FROM `default_produtos` WHERE `precocib` BETWEEN 17490,00 AND 17490,00
so how i can resolve this problem??
Try this one
$this->db->where("FORMAT(REPLACE(precocib, ',', ''), 2) BETWEEN REPLACE($faixaDe, ',', '') AND REPLACE($faixaAte, ',', '')");
REPLACE(str,from_str,to_str)
Remove comma(,) from the 17490,00 AND 17490,00. I think it will be helpfull for you.
I am trying to add page via code in Concrete5(CMS).
$parentPage = Page::getByPath("/hotel");
$ct = CollectionType::getByHandle("products");
$data = array();
$data['cName'] = 'New Page';
$data['cDescription'] = 'Description here';
$newPage = $parentPage->add($ct, $data);
But I get MySql error:
mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1] in EXECUTE("select max(cDisplayOrder) from Pages where cParentID = LIMIT 1")
And also How can I add an Attribute when created page??
The SQL error implies to me that the $parentPage wasn't instantiated properly. C5 is confusing in that the Page::getBy...() and a few others will return an object even if the page doesn't exist -- it's your responsibility to check it for errors.
Are you expecting that /hotel exists? You have to create it first. You should var_dump($parentPage) after you've loaded it.
I have a problem with a query. This query works with phpMyAdmin, but I have an error when this query is execute by PHP. What could be the reason?
My PHP code is:
var_dump($sql);
query($sql);
when I debug:
this is the query string:
UPDATE searchcolumnsets SET name = "Project X",jsonfields = "[{\"name\":\"cm:contentPropertyName\",\"title\":\"Thumbnailed Content Property Name\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:defaultHomeFolderPath\",\"title\":\"Percorso cartella homepage\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"trx:enabled\",\"title\":\"Abilitato\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:identifier\",\"title\":\"Identificativo\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:expiryDate\",\"title\":\"Data di scadenza\",\"description\":\"Data di scadenza\",\"datatype\":\"d:date\"},{\"name\":\"cm:hits\",\"title\":\"Conteggio\",\"description\":\"Conteggio\",\"datatype\":\"d:int\"}]" WHERE id = 50
this is the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name":"cm:contentPropertyName","title":"Thumbnailed Content Property Name","desc' at line 1
you may use single qoute instead.
try this
UPDATE searchcolumnsets SET name = 'Project X',jsonfields = '[{\"name\":\"cm:contentPropertyName\",\"title\":\"Thumbnailed Content Property Name\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:defaultHomeFolderPath\",\"title\":\"Percorso cartella homepage\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"trx:enabled\",\"title\":\"Abilitato\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:identifier\",\"title\":\"Identificativo\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:expiryDate\",\"title\":\"Data di scadenza\",\"description\":\"Data di scadenza\",\"datatype\":\"d:date\"},{\"name\":\"cm:hits\",\"title\":\"Conteggio\",\"description\":\"Conteggio\",\"datatype\":\"d:int\"}]' WHERE id = 50