mercredi 14 septembre 2016

can i use IF/ELSE in MYSQL or PHP to save previous row, compare it to the present row, and leaving out duplicated information in output?

I have written a php script file that gives the output in a pdf on a weekly basis , image one is my current output. I want to get my output to be something like image one. any help would be appreciated.

conditions:

  1. If it is the same radio ID and same event type print only the date Time column .
  2. if it is same radio ID and different event Type , print only event type and date stamp.
  3. a name can have multiple radio Ids.

this is my select statement :

$query = "SELECT Events.*,Types.description AS channel_description, subs.name AS name FROM Events LEFT JOIN Types ON Types.channel_type_id = Events.channel_type_id LEFT JOIN Subscribers AS subs ON subs.radio_id=Events.radio_id AND subs.network_id=2 WHERE event_type_id ='V' AND Events.radio_id IN ( ";

$query .="SELECT Subscribers.subscriber_id FROM Subscribers ";

$query .= "WHERE network_id=2 AND  dealer_id='".$customer['cust_id']."')";

$query .= " AND event_date > DATE_SUB(DATE_SUB(curdate(), INTERVAL 3 WEEK), INTERVAL DAYOFWEEK(curdate()) DAY) ORDER BY Events.subscriber_id DESC, Events.event_time ASC";

[desired output

[current output

Aucun commentaire:

Enregistrer un commentaire