Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am working on an app in CodeIgniter, but I am not able to write the following query using active records,
select price, count(*) from fake_apps where downloads > 20000 group by price;
How can I write this query using CodeIgniter's active records?
Thank You.
$this->db->select("price,count(*)",FALSE);
$this->db->from("fake_apps");
$this->db->where("downdoad>","20000");
$this->db->group_by("price);
$res = $this->db->get();
It would be like this:
$this->db->select("price, count(*)",FALSE);
$this->db->where("downdoad > ","20000");
$this->db->group_by("price");
$sql = $this->db->get("fake_apps");
echo '<pre>';
print_r($this->db->last_query());
echo '</pre>';
For FALSE in Codeigniter select:
$this->db->select("price, count(*)",FALSE);
Note:
If you set it to FALSE, CodeIgniter will not try to protect your field
or table names with backticks. This is useful if you need a compound
select statement.
Reference:
https://ellislab.com/codeigniter/user-guide/database/active_record.html
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a database where i store my photos title, tags, and their path on sever some of the records have names like:
photo 1234.png. I need to make them like photo1234.png
Why can't I use a query like
UPDATE tblPhoto a
set a.photoLink = replace(a.photoLink , ' ', '')
where a.photoLink like '% %';
And which is the best way to rename them in Linux Server, can I use php ?
You don't need where clause
UPDATE tblPhoto SET photoLink = REPLACE(photoLink , ' ', '');
For replacing the file name on your Linux Server you can try to look in this answer.
https://stackoverflow.com/a/2709619/7921383
Use php method for example:
$old_name="Hello World";
echo str_replace(" ","",$old_name);
//output Helloworld
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I try to login a user account on my Page, I get the following error:
Table 'mysql.users' doesn't exist
I have checked that I have only one 'mysql' table and that is named User not Users.
Someone please guide me how to get rid of this error. Can I change the Table name to "User"?
Right now I have the following code:
query("SELECT * FROM `users` WHERE `username`='" . $mysqli-
real_escape_string($useroremail) . "' and `password`='" . md5($password) . "'
and `userlevel`='".($vendor==true ? 30 : 20)."'LIMIT 1;") or die($mysqli->error);
Can i change the Table name to "User"?
Yes you can.
Try this.
RENAME TABLE `oldTableName` TO `newTableName`
RENAME TABLE 'Users' TO `User`
Hope this helps.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I used Bootstrap datepicker to get date from the user. I stored that value in database.
But when i render this date in html, it showed unexpected value with the date !
I give the screen shot of the result.
Can anyone help me to solve this ?
How have you stored the date in the database?
Make sure you used DATETIME and not VARCHAR
Also how did you get the date from the database?
I would use:
$query = "SELECT DATE_FORMAT(ColumnName, '%Y-%m-%d %H:%i:%s') AS Date FROM Table";
$result = mysqli_query($cxn,$query) or die(mysqli_error());
$date = $result->fetch_object()->Date;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database table have this value,i have to check this email value 'abc#gmail.com' is exist in the database or not.
abc#gmail.com
edf#dfg.com
xyz#abcinfo.com
12345#fdfg.com
If 'abc#gmail.com' value is exist in the database table, output is true else false, so how to write the query for this to achieve?
thanks
Kumar
You can do something as simple as
select CASE WHEN count(1) > 0 THEN 'true' ELSE 'false' END from table where email = 'abc#gmail.com'
But you should give some more information for a beater answer.
you can write query like
SELECT IF(COUNT(*) >0, TRUE,FALSE)as response FROM <tablename> WHERE emailid='edf#dfg.com';
select exists(
SELECT 1 FROM <tableName> WHERE email LIKE 'abc#gmail.com'
)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis