$qry="(SELECT @n := @n +1,s.shipmentid,s.fare, s.commission, o.driver, s._date, v.vehiclenumber, p.productname, rs.routename AS source, rd.routename AS destination,
o.ownername,s._time
FROM (SELECT @n :=0)initvars,route AS rs, route AS rd, shipment AS s, product AS p, vehicle AS v, owner AS o
WHERE s.vehicle = v.vehicleid
AND s.source = rs.routeid
AND v.owner = o.ownerid
AND s.destination = rd.routeid
AND s.product = p.productid
AND v.vehiclenumber = 'LSB-2345'
and s._date between '2011-03-01 '
and '2011-03-30')
UNION all
(SELECT
null, null, SUM(s.fare), SUM(s.commission), null, null, null, null,
null, null, null,null
FROM route AS rs, route AS rd, shipment AS s, product AS p, vehicle AS v, owner AS o
WHERE s.vehicle = v.vehicleid
AND s.source = rs.routeid
AND v.owner = o.ownerid
AND s.destination = rd.routeid
AND s.product = p.productid
AND v.vehiclenumber = 'LSB-2345'
and s._date between '2011-03-01'
and '2011-03-30')";
$result=mysql_query($qry);