[Solved] Rolling up addition using MySQL

SELECT x.* , x.cf1+x.cf2 sub_total , SUM(y.cf1+y.cf2) running FROM 1_bugs x JOIN 1_bugs y ON y.id <= x.id GROUP BY x.id; +—-+————+—–+—–+———–+———+ | id | date | cf1 | cf2 | sub_total | running | +—-+————+—–+—–+———–+———+ | 1 | 2016-07-19 | 3 | 2 | 5 | 5 | | 2 | 2016-07-19 | 2 … Read more

[Solved] add 1 day to date format YYYYMMDD when field name is greater or equal to 1200 [closed]

With the help of STR_TO_DATE and DATE_FORMAT function you can achieve this: SELECT DATE_FORMAT(STR_TO_DATE(dateUs,’%Y%m%d’) + INTERVAL HourMins+0 >= 1200 DAY ,’%Y%m%d’) AS dateLoc FROM your_table Demonstration: SET @str := ‘20160919’; SET @HOUR := ‘1215’; SELECT ( STR_TO_DATE(@str, ‘%Y%m%d’) + INTERVAL (@HOUR + 0) >= 1200 DAY ) AS date, DATE_FORMAT( STR_TO_DATE(@str, ‘%Y%m%d’) + INTERVAL (@HOUR … Read more

[Solved] mysqli_query() expects parameter 3 to be long

Just call 2 queries separately like this : if($money >= 400) { $query1 = “UPDATE users SET spam = spam + 1, money = money – 400 WHERE user_id=”.$_SESSION[‘user’]; $query2 = “UPDATE users SET score = score + 2500 WHERE user_id=”.$_SESSION[‘user’]; $update1 = mysqli_query($conn,$query1); // call 1st query $update2 = mysqli_query($conn,$query2); // call 2nd query … Read more

[Solved] Which phone has got high sales in each year?

In the derived table the total sales are calculated at ( year,phone ) combination. Once the total sales are calculated all the top rows( rank = 1 by sales ) should be identified for each year. By using correlated sub-queries and having clause the first row is identified from each group( year ) and displayed … Read more

[Solved] How to get data 3 tables?

You need to do a join on the tables in order to get the columns of all of them. Warning: using * to get all columns is bad practice. You should qualify (name) all the columns you need. Here is an example: SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.key2 = t2.key2 … Read more

[Solved] Select database where datetime>now()? [closed]

Store now() in a variable and then compare using where clause. Also see this and this Update :<?php $timeZone=”Asia/Kolkata”; //variable for indian timezone date_default_timezone_set( $timeZone); //default timezone set to indian time $now = date(“m/d/y G.i:s”); echo $now; ?> Check for date functions in PHP 2 solved Select database where datetime>now()? [closed]

[Solved] how to insert Json object in database [closed]

Example of database connection : //ENTER YOUR DATABASE CONNECTION INFO BELOW: $hostname=”localhost”; $database=”dbname”; $username=”username”; $password=”password”; //DO NOT EDIT BELOW THIS LINE $link = mysql_connect($hostname, $username, $password); mysql_select_db($database) or die(‘Could not select database’); Exemple of INSERT array in database : $json = file_get_contents(‘php://input’); $obj = json_decode($json,true); //Database Connection require_once ‘db.php’; /* insert data into DB */ … Read more

[Solved] Retrieve records from Multiple tables using Join

I made the assumption that this is SQL Server and it didn’t look like there was a where clause requirement so I provided this query for that. If you need for mysql please update question. Select co.com_name,c.c_name,b.b_id,b.b_name from Country c inner join Company co on c.c_id = co.c_id inner join branch b on co.com_id = … Read more

[Solved] Search query using php and mysql [closed]

Try this: $query = “select * from table_name where 1 “; if(!empty($_POST[‘field1’]) ) { $query .= ” AND field1 like ‘”.trim($_POST[‘field1’]).”‘”; } if(!empty($_POST[‘field2’])) { $query .= ” AND field2 like ‘”.trim($_POST[‘field2’]).”‘”; } // and so on $result = mysql_query($query); 1 solved Search query using php and mysql [closed]

[Solved] how to fetch data from database in php if i have two table in database and i want to fetch from one table user id to others table data [closed]

As database schema is not available, I’m assuming the structure like this. Change it where you need. registration table Id | firstName | lastName | email | …. Where, Id is Primary Key and auto-incremented orders table orderId | userID | orderName | … Where, orderId is Primary Key and auto-incremented ; userID is Id … Read more