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;
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 5 years ago.
Improve this question
I am trying to add random number in one of my database column called likes which have about 5000 row in it. currently I have tried like below to get random number from 10 to 50.
$randomnumberlike = (rand(10,50));
but this is setting same number in all row...instead I want different number in row...anyone can please suggest how can I do it ?
Thanks
Try: UPDATE Table SET fieldName = ((rand() * 1000) % 40) + 10;
Because when you preset it in a variable, it'll be the same for all...
You're setting a variable:
$randomnumberlike = (rand(10,50));
If you're then using $randomnumberlike to add to the db then it will always be the same, its already be assigned (unless within a loop), you need to use (rand(10,50)) (or working similar) directly in the query like this:
UPDATE <table_name> SET <field_name> = ROUND((RAND() * (50-10))+10) WHERE ...;
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
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 want to retrieve all the properties in the range 2200000(min_price) to 2700000(max_price)
The query should look like
SELECT *
FROM properties
WHERE ( ((raw_min >= '{$min_price}')
OR (raw_min <= '{$max_price}'))
AND ((raw_max >= '{$min_price}')
OR (raw_max <= '{$max_price}')))
AND (..)
query should satisfy the below 6 conditions
raw_min - raw_max
(1) 1000000-2000000 (false)
(2) 1500000- 2400000 (true)
(3) 2300000-2600000 (true)
(4) 2500000-3000000 (true)
(5) 3200000-5000000 (false)
(6) 2000000-3000000 (true)
Please try this query:-
SELECT *
FROM properties
WHERE (raw_min between 2200000 AND 2700000)
OR (raw_max between between 2200000 AND 2700000)
OR (raw_min <= 2200000 && raw_max >= 2700000)
Please check I have updated the query.
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