0

i want to display last 3 months of data. but this query is not working. it showing empty results.
please some one help me.

$sql8 = mysql_query("SELECT `orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`,user_id,userName,date FROM `orderlist` WHERE `user_id`='$userid' AND `userName`='$usern' AND date=DATE(NOW()) - INTERVAL 3 MONTH");


                $i=0;
              while($row8 = mysql_fetch_array($sql8))
              {

                    $no = $row8['orderlist_id'];
                    $i++;


             echo '<tr bordercolorlight="#B0A982"><td>'.$i.'</td><td>'.$row8["brandname"].'</td>';
             if($_GET['orderid'] == $no)
             {
                echo '<td><form name="orderquantity" method="post" action="changequantity.php?id='.$_GET['orderid'].'"><input type="text" size="10" name="change_quantity" value="'.$row8["quantity"].'">
                <input type="hidden" name="price" value="'.$row8["ourRate"].'">
                <input type="submit" name="ch_quantity" value="Update"></form></td>';
             }
             else
             {
                 echo '<td>'.$row8["quantity"].'</td>';
             }
             echo '<td>'.$row8["packsize"].'</td><td>Rs. '.$row8["mrp"].' </td><td>Rs. '.$row8["ourRate"].'</td><td>Rs. '.$row8["Sum"].'</td></tr>';
6
Contributors
19
Replies
89
Views
3 Years
Discussion Span
Last Post by Taywin
0

Use the following query:

SELECT orderlist_id, brandname, packsize, quantity, mrp, ourRate, Sum, user_id, userName, date
FROM orderlist
WHERE user_id = '$userid'
AND userName = '$usern'
AND date >= NOW() - INTERVAL 3 MONTH;
0

You try following query, Your query may be not giving result because you are using equal to sign, so it is searching exact records for that particular single date.

Following query will give all result that happened in last 3 months.

Remove > sign if you want to equate only

$sql8 = mysql_query("SELECT `orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`,user_id,userName,date FROM `orderlist` WHERE `user_id`='$userid' AND `userName`='$usern' AND date>=date_sub( current_date(),interval 3 month);

Edited by urtrivedi

0

i want to display last 3 months of data

When you say last 3 months, so by default it means last three months from current date (today).

0

except current date data means what should i do? month wise i have to display.

0
$sql8 = mysql_query("SELECT `orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`,user_id,userName,`date` FROM `orderlist` WHERE `user_id`='$userid' AND `userName`='$usern' AND `date`>date_sub( current_date(),interval 3 month)");

No need to rename field, you can enquote field name with ` character (press key before 1 on keyboard)

I have removed = sign from query condition, so it will not display current date record, but it will only show last three month records.

What kind of monthly output you want.

Edited by urtrivedi

0

i checked in database also but again it showing all the records.
the current month is august, before june and july data's i want to display seperate.

Edited by malatamil: 1

0

first is my actual table (test.png).
after
SELECT orderlist_id, brandname, packsize, quantity, mrp, ourRate, Sum,user_id,userName,date FROM orderlist WHERE user_id='2' AND userName='admin2' AND date>date_sub( current_date(),interval 2 month)

it show like second table(test1.png). but i want to display
orderlist_id=12,19 sepatately because month is different.so i have to use loop?

Attachments test1.png 20.59 KB test.png 41.19 KB
0

You're not making much sense.

but i want to display orderlist_id=12,19 sepatately because month is different.so i have to use loop?

The orderlists 12 and 19 are listed separately.

0

sorry for asking.. i checked directly in database with this query

SELECT orderlist_id, brandname, packsize, quantity, mrp, ourRate, Sum,user_id,userName,date FROM orderlist WHERE user_id='2' AND userName='admin2' AND date>date_sub( current_date(),interval 2 month)

but am not getting correctly. if i have to do any changes in that above query.

0

We don't have your tables so we can't check your query. Pritaeas asked you to provide a sql dump, but you just gave a screenshot, which is not very useful. If you make an SQL dump and paste it here, then we can copy it and create our own version of your tables. Otherwise it's going to be very difficult.

0

here i added orderlist table

Table structure for table `orderlist`
--

CREATE TABLE IF NOT EXISTS `orderlist` (
  `orderlist_id` int(11) NOT NULL AUTO_INCREMENT,
  `brandname` varchar(100) NOT NULL,
  `packsize` varchar(5) NOT NULL,
  `quantity` varchar(1) NOT NULL,
  `mrp` varchar(10) NOT NULL,
  `ourRate` varchar(10) NOT NULL,
  `Sum` varchar(20) NOT NULL,
  `user_id` int(11) NOT NULL,
  `userName` varchar(20) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`orderlist_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;

--
-- Dumping data for table `orderlist`
--

INSERT INTO `orderlist` (`orderlist_id`, `brandname`, `packsize`, `quantity`, `mrp`, `ourRate`, `Sum`, `user_id`, `userName`, `date`) VALUES
(11, 'Boost', '200 G', '1', '45', '42', '42', 1, 'admin', '2014-06-04'),
(12, 'Boost', '100 G', '2', '20', '18', '36', 2, 'admin2', '2014-07-11'),
(13, 'Red Label', '500 G', '1', '100', '96', '96', 1, 'admin', '2014-07-11'),
(14, 'Tata Agni', '250 G', '2', '35', '32', '64', 1, 'admin', '2014-08-14'),
(15, 'Bru', '500 G', '1', '90', '88', '88', 1, 'admin', '2014-08-14'),
(16, 'Nescafe Classic', '1 Kg', '1', '150', '147', '147', 1, 'admin', '2014-08-14'),
(17, 'Yippee Noodle', '100 G', '2', '25', '24', '48', 1, 'admin', '2014-08-16'),
(18, 'Maggi - Vegetable atta', '200 G', '1', '30', '28', '28', 1, 'admin', '2014-08-16'),
(19, 'BournVita -Litl champ', '250 G', '2', '30', '28', '56', 2, 'admin2', '2014-08-18'),
(20, 'Nescafe Classic', '500 G', '1', '50', '48', '48', 2, 'admin2', '2014-08-19'),
(21, 'Yippee Noodle', '100 G', '2', '25', '24', '48', 2, 'admin2', '2014-08-19'),
(22, 'Red Label', '500 G', '1', '100', '96', '96', 2, 'admin2', '2014-08-19');
0

but i want to display orderlist_id=12,19 sepatately because month is different

I don't really get what this part mean... :( A graphical sample should be able to clearly explain it...

0

1.username = admin and id = 1 means(t1.png)

SELECT orderlist_id, brandname, packsize, quantity, mrp, ourRate, Sum,user_id,userName,date FROM orderlist WHERE user_id='1' AND userName='admin'

Last 3 months
2.username = admin and id = 1 and month=august-2014 (t2.png)
3.username = admin and id = 1 and month=july-2014
4.username = admin and id = 1 and month=june-2014

front end page look like this(t3.png)

Attachments t3.png 34.16 KB t2.png 17.77 KB t1.png 23.44 KB
0

So you mean you want to display the previous 3 months in each table? If so, you could still call SQL one time to gather all 3-previous-month data sorted by date with decending order (use the working query you did before but add order by date desc). Then start iterating through each of the data in PHP to display. While iterating, keep checking if the month has changed. If it is changed, display a new table. Is that what you want to do???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.