Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Here is my solution (uses the tables I suggested earlier in #12) Yellow cells are partially booked, red cells fully booked, green have no bookings. Hovering over yellow shows the available slots. Output attached
  2. A recursive search might do it $sql = "SELECT id , ser_in , ser_out FROM repair"; $res = $db->query($sql); $data = array(); while (list($id,$in,$out) = $res->fetch_row()) { $data[$out][] = [$in, $id]; } history($data, 'C'); function history(&$data, $ser, $level=0) { foreach ($data[$ser] as $s) { $indent = str_repeat('--- ', $level); if ($ser != '')echo "$indent $s[0] | $ser (record $s[1])<br>"; if ($s[0]==$ser) { return; } history($data, $s[0], $level+1); } } /******** RESULTS ********** B | C (record 3) --- A | B (record 2) --- --- A | A (record 1) C | C (record 4)
  3. I don't have your data so I created my own. +------------------+------------+------------+---------+ | meter_reading_id | account_id | date_read | reading | +------------------+------------+------------+---------+ | 1 | 121 | 2015-12-25 | 9999332 | | 2 | 121 | 2016-01-25 | 9999727 | | 3 | 121 | 2016-02-25 | 9999949 | | 4 | 121 | 2016-03-25 | 242 | | 5 | 121 | 2016-04-25 | 510 | | 6 | 122 | 2015-12-15 | 9999214 | | 7 | 122 | 2016-01-15 | 9999473 | | 8 | 122 | 2016-02-15 | 9999872 | | 9 | 122 | 2016-03-15 | 167 | | 10 | 122 | 2016-04-15 | 473 | | 11 | 123 | 2015-12-16 | 9999316 | | 12 | 123 | 2016-01-16 | 9999695 | | 13 | 123 | 2016-02-16 | 9999941 | | 14 | 123 | 2016-03-16 | 197 | | 15 | 123 | 2016-04-16 | 510 | | 16 | 124 | 2015-12-20 | 9999277 | | 17 | 124 | 2016-01-20 | 9999600 | | 18 | 124 | 2016-02-20 | 9999700 | | 19 | 124 | 2016-03-20 | 9999800 | | 20 | 124 | 2016-04-20 | 9999986 | | 21 | 125 | 2015-12-21 | 9999227 | | 22 | 125 | 2016-01-21 | 9999512 | | 23 | 125 | 2016-02-21 | 9999793 | | 24 | 125 | 2016-03-21 | 132 | | 25 | 125 | 2016-04-21 | 362 | +------------------+------------+------------+---------+ You can apply the method to your data. The target will be to get the usage for each account for the period Jan 1st to Mar 31st. To do this you need, for each account last reading prior to Jan 1st last reading prior to Mar 31st then find the difference, adjusting those that have gone over the 10M. Method is to find the latest (MAX) date required then match the reading dates to find the reading on that date So SELECT r1.account_id , r1.reading as initial , r2.reading as final , CASE WHEN r2.reading < r1.reading THEN 10000000 + r2.reading - r1.reading ELSE r2.reading - r1.reading END as acc_usage FROM ( SELECT m1.account_id, m1.reading FROM meter_reading m1 JOIN ( SELECT account_id , MAX(date_read) as date_read FROM meter_reading WHERE date_read < '2015-01-01' GROUP BY account_id ) mx1 USING (account_id, date_read) ) r1 JOIN ( SELECT m2.account_id, m2.reading FROM meter_reading m2 JOIN ( SELECT account_id , MAX(date_read) as date_read FROM meter_reading WHERE date_read < '2015-04-01' GROUP BY account_id ) mx2 USING (account_id, date_read) ) r2 ON r1.account_id = r2.account_id ORDER BY account_id; +------------+---------+---------+-----------+ | account_id | initial | final | acc_usage | +------------+---------+---------+-----------+ | 121 | 9999332 | 242 | 910 | | 122 | 9999214 | 167 | 953 | | 123 | 9999316 | 197 | 881 | | 124 | 9999277 | 9999800 | 523 | | 125 | 9999227 | 132 | 905 | +------------+---------+---------+-----------+
  4. Looks like INTERVAL works only on DATETIME and not TIME columns, so needs SUBTIME() INSERT INTO test (timecol1, timecol2) VALUES ('03:00', SUBTIME('03:00', '1:00'));
  5. So your your times are not in TIME format then? What format are they?
  6. Use DECIMAL type for currency
  7. INSERT INTO tablename (col1, col2) VALUES ('$t1', '$t1' - INTERVAL 1 HOUR)
  8. To make your second code equivalent to the first you would echo $p. <?php $i = 2; $p = $i++; // value assigned to $p then $i is incremented echo $p; //--> 2 echo $i; //--> 3 ?>
  9. You need to join the table to itself on the subject column then apply your search criteria in a WHERE clause
  10. This query will give the info you need for each date in the bookings table for the current year/month SELECT b.date , SUM(IF(t.timeslot_id IS NULL,0,1)) as bookedcount , free.freeslots FROM booking b LEFT JOIN ( SELECT date , GROUP_CONCAT(DISTINCT TIME_FORMAT(x.start_time, '%H:%i') ORDER BY start_time SEPARATOR ', ') as freeslots FROM ( SELECT DISTINCT b.date , t.timeslot_id , t.start_time FROM booking b CROSS JOIN timeslot t WHERE YEAR (b.date) = '2015' AND MONTH(b.date) = 1 ) as x LEFT JOIN booking b USING (date,timeslot_id) WHERE b.timeslot_id IS NULL GROUP BY date ) as free USING (date) LEFT JOIN timeslot t USING (timeslot_id) WHERE YEAR (b.date) = '2015' AND MONTH(b.date) = 1 GROUP BY b.date; EG +------------+-------------+---------------------------------------------+ | date | bookedcount | freeslots | +------------+-------------+---------------------------------------------+ | 2015-01-19 | 7 | 09:00, 10:30, 11:30, 13:00, 13:30, 14:00, | | | | 15:30, 16:00, 16:30, 17:00, 17:30 | +------------+-------------+---------------------------------------------+ | 2015-01-20 | 4 | 10:30, 11:00, 11:30, 12:00, 12:30, 13:00, | | | | 13:30, 14:00, 14:30, 15:00, 15:30, 16:30, | | | | 17:00, 17:30 | +------------+-------------+---------------------------------------------+ | 2015-01-21 | 3 | 09:00, 10:30, 11:00, 11:30, 12:00, 12:30, | | | | 13:00, 13:30, 14:00, 14:30, 15:00, 15:30, | | | | 16:30, 17:00, 17:30 | +------------+-------------+---------------------------------------------+ | 2015-01-23 | 18 | NULL | +------------+-------------+---------------------------------------------+ This will enable you to colour-code your days to show whether fully booked, partially booked or completely free by applying the appropriate class name. If you also apply a classname of, say, "date" for non-blank cells you can apply a click function to all ".date" cells which passes the cell's date to your booking form page
  11. What makes you think that would be "easier"?
  12. Use the <> button in the toolbar when posting code. Your timeslot table should just define the daily timeslots. This then defines the times for your time booking form and by comparing these times with booked times on a day you know if there are spare unbooked slots. Have a user table to store name, phone etc - don't repeat in every booking. So you tables would look like this
  13. You wouldn't store any of those items in a database, you should be able to derive them from the existing post data when required.
  14. yes, and bookings
  15. What does your data table/s look like?
  16. First recommendation is for you to use CSS styles EG <style type="text/css"> table { border-collapse: collapse; } td.free { text-align: center; background-color: white; } td.booked { background-color: #FF8080; } </style> When you move on to a new month, query your db for appointments in that month and store in an array, keyed by day number. Then it is easy to look up each day as you out put it in the table and give it the appropriate class name to style it. Make each cell with a date clickable so you can display the form for that day (jquery is the easiest method).
  17. 1. You need to assign the results of a SELECT query to a result object 2. mysqli_query requires the db connection object as the first argument 3. mysqli_fetch_xxxxx requires the result object as the argument. All you need is a single INSERT ... SELECT query. INSERT INTO admin (username, password, age, phonenumber, nationality) SELECT username, password, age, phonenumber, nationality FROM login WHERE username='$searchq'
  18. That seems to be same problem I pointed out to you last October http://forums.phpfreaks.com/topic/291987-if-then-question/?do=findComment&comment=1494981 You need the reading at the beginning of the period and the reading at the end then subtract one from the other. If it is negative, add 10M.
  19. You need look no further than the PHP manual for mail() function
  20. Sounds like you would have something like the model attached below. This assumes a particular option applies to a single submodel As for your selection then maybe have a series of linked dropdowns. A dropdown menu of series A dropdown of those models belonging to the series selected in menu 1 A menu of those submodels belong to the selected model A menu of the options for the selected submodel A menu of products belonging to the selected option
  21. I don't know the output you want but this should get you on your way $xml = new SimpleXMLElement($_xml_string); foreach ($xml->xpath("//Outcome") as $out) { $oid = $out['id']; foreach ($out->Bookmaker as $bk) { $bkname = $bk['name']; $bklu = $bk['lastUpdate']; foreach ($bk->Odds as $odd) { $outcomes[] = array ( 'Outcome' => (string)$oid, 'Bookmaker' => (string)$bkname, 'Updated' => (string)$bklu, 'Bet' => (string)$odd['bet'], 'SP' => (string)$odd['startPrice'], 'CP' => (string)$odd['currentPrice'], 'Decimal' => convertPrice ((string)$odd['currentPrice']) ); } } } function convertPrice($price) { list ($a,$b) = explode('/', $price); return $a/($a+$b); } function priceSort($a, $b) { return strcmp($a['Decimal'], $b['Decimal']) ; } usort($outcomes, 'priceSort'); echo '<pre>',print_r($outcomes, true),'</pre>';
  22. I can see the problem but am unable to help without confessing to being a pimp. Sorry.
  23. If you had posted the original xml then I would look at it. I am not prepared to spend all evening editing print_r() output into something that can be processed.
  24. A table subquery needs to be given a table alias SELECT * FROM ( SELECT ... ) as top9 ORDER BY RAND()
  25. Make the $_SERVER["HTTP_X_MXIT_USERID_R"] value part of a unique key in your table then it becomes impossible to write a duplicate. EG> UNIQUE KEY (poll_id, user_id)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.