PHP - MySQL
-
» MariusI have SQL a query like this:
SELECT c.type, SUM( u.account )
FROM contracts c, u_data u
WHERE c.user_id = u.id
GROUP BY c.type;
Now this gives me...Last post » AdminHi,
You just have the wrong order for GROUP BY and ORDER BY.
ORDER BY should be added after GROUP BY.
...
GROUP BY c.type;
ORDER BY FIELD( c.type,...
-
» MariusHi
I have an array in php:
$arr = array(3, 'value 1', 'other value');
And a mysql table with these columns: id | name | data
I want to store...Last post » AdminHi
You can store an array in a database into a string with JSON format.
Use json_encode() when you want to insert the array. For example:...
-
» MariusI'm trying to SELECT from a PHP array inside a mysql query.
$sql = SELECT * FROM table WHERE id = $ids ;
$ids has been created by $_POST and...Last post » AdminTry with IN with implode of the array $id like:
$sql = SELECT * FROM table WHERE id IN ( . implode(',', $ids) . ) ;
- Make sure that $ids is an...
-
» MariusI've written following code to compare a date in a variable with today's date. If the date in a variable is greater than today's date the error...Last post » AdminYou may be meaning 11th Decemeber with 12-11-2014, but strtotime isn't seeing it that way.
If you need to use strtotime() then change the input...
-
» MariusHello,
I have two tables: A and B. I need to compare their columns to get values of one table that are not in other table.
Table A columns : ID,...Last post » AdminHi,
You can use not in :
SELECT *
FROM table_A
WHERE table_id NOT IN (SELECT id from table_B)
-
» MariusI have a subscription system in my website. When the users subscribe, their start date and time is added in mysql table using now() function.
I also...Last post » AdminThe date_add() function is what you're looking for:
DATE_ADD(date,INTERVAL expr unit)
Example
INSERT INTO users
(username, registration_date,...
-
» MariusWhile executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my...Last post » AdminHi,
If you just want to skip rows with duplicate values, and no update needed, I think that is proper to use INSERT IGNORE .
If you use INSERT...
-
» MariusHello,
I have this Select query, I want to select one row from mysql table, where id = $id, and has x_name or y_name 'yes'.
$insert_cat =...Last post » AdminHi
The problem is that you didn't separate the conditions with the OR from the id=$id, so to select just the row which has that $id AND 'yes' in any...
-
» MariusHi
I have this array, and I want to return it as JSON from a PHP script.
$ar = array(
'k0'=> array('a', 'b', 'c'),
'k1'=> array(1, 2, 3)
);...Last post » MarPloHi,
Use json_encode() to encode the data and set the content-type with header('Content-type: application/json');
Anyway, it works fine if you just...
-
» MariusHi
I have two arrays $a1 and $a2 with various elements.
How can I check which item from $a2 is in $a1? Is there any function, or I have to traverse...Last post » AdminHi,
The array_intersect($a2, $a1) function returns the elements of $a2 which are found in $a1.
Also, with the in_array() function you can check if...
-
» MariusI have 2 tables with same column names in my database which are supposed to provide content in 2 languages.
This is how I query for one table (this...Last post » MarPloThe mysql is confused when you select columns with same name. The solution is to use Alias ( AS ).
$sql = SELECT en.col1 AS c1en, en.col2 AS c2en,...
-
» MariusHi
Does anyone has a php code to display the elapsed time?
Like: one hour ago, 1 day and 3 hours ago, ...
Thank you.Last post » AdminHi
You can use the timeElapsed() function, from this example:
function timeElapsed($t1, $t2 = null) {
/*...
-
» MariusWhy in my database, time is of type Timestamp but has no numeric form: 1402008961, but is of the form: 07/25/2014 12:13:45 ?Last post » MarPloHello
Timestamp in MySQL is different from Unix Timestamp, which as you know is a number of seconds starting from 1970.
Timestamp in MySQL is...