Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Sorry, it would come from the "business" input. $id = intval($_POST['business']);
  2. Check the query that is actually submitted by echoing the final SQL string that is executed echo "select count(*) as t from utilizador".$se; It helps debugging if you always build the sql as a string variable first then execute that.
  3. I grovel on my knees, Sir. Please accept my most humble apologies for missing your comments and just reading your code.
  4. Let me get it straight. You have a page that does this $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; Then a page that decides whether to go to Q2 or Q3 that does this (even though there is no mention of Q2) $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; $_SESSION['Q1'] = $_POST['Q1']; $_SESSION['comment1'] = $_POST['comment1']; then the Q2 page <title>Question 2</title> </head> <body> <?php session_start(); $name = $_SESSION['name']; $cslogin = $_SESSION['cslogin']; $domain = $_SESSION['domain']; $project = $_SESSION['project']; $ODM = $_SESSION['ODM']; $hwphase = $_SESSION['hwphase']; $ppmid = $_SESSION['ppmid']; $survey = $_SESSION['survey']; $month = $_SESSION['month']; So my question was "When going to the second above, how are the POST vars re-sent?" You wouldn't need to - just re-use the session vars. Don't reset them to the (empty) post vars.
  5. The id you want to update would come from $_POST['voteall'] if(isset($_POST['voteall'])) { $id = intval($_POST['voteall']); // ensure it's an integer $vote_lg = "update membertest set vote=vote+1 where id = $id"; $run_lg = mysqli_query($con, $vote_lg) or die(mysqli_error($con)); }
  6. It can be both. <?php echo '<pre>',print_r($_REQUEST, true),'</pre>'; ?> <form action='?id=321' method='post'> Name <input type="text" name="name" value="Fred" size="10"> <input type="submit" name="btnSubmit" value="Submit"> </form> which give this when the form is submitted Array ( [id] => 321 // from URL [name] => Fred // from posted form field [btnSubmit] => Submit // from posted form field ) However, in this instance, I would put the id in a hidden form field so everything is POSTed rather than have a mixture
  7. How are you re-sending the POST data to that intermediate page? If you aren't then all the session vars will be overwritten and set to empty.
  8. Either Echo to the page and view the source Echo it to the page using htmlentities() echo htmlentities($xml_string); then you can copy/paste it.
  9. while($employees=mysql_fetch_assoc($records)) { $data .= "<td>".$Employee['ID']."</td>"; Those should match.
  10. You have your clauses in the wrong order, Should be UPDATE .... SET.... WHERE ....
  11. It isn't too difficult. I defined a class to highlight the cell with a 4 pixel border td.now { border: 4px solid #883A66; width: 19px; height: 11px; padding: 0; } then applied that class to the cell with selected date.
  12. There is an example of that in the code I posted
  13. mysqli_error function require the connection as a parameter mysqli_error($con)
  14. 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
  15. 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)
  16. 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 | +------------+---------+---------+-----------+
  17. 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'));
  18. So your your times are not in TIME format then? What format are they?
  19. Use DECIMAL type for currency
  20. INSERT INTO tablename (col1, col2) VALUES ('$t1', '$t1' - INTERVAL 1 HOUR)
  21. 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 ?>
  22. You need to join the table to itself on the subject column then apply your search criteria in a WHERE clause
  23. 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
  24. What makes you think that would be "easier"?
  25. 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
×
×
  • 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.