Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I wouldn't use a text area for input that relies on the user using the correct delimiter. You have no control whatsoever over the format. It would be better IMO to have several separate text inputs each named "proxies[]" <input type="text" name="proxies[]" size="25" /><br/> <input type="text" name="proxies[]" size="25" /><br/> <input type="text" name="proxies[]" size="25" /><br/> <input type="text" name="proxies[]" size="25" /><br/> <input type="text" name="proxies[]" size="25" /><br/> This way the individual proxies are separated and $_POST['proxies'] will already be your required array
  2. Are you saying that "add.php" gives blank output? Is the record being inserted? What output are you expecting, other than an error message if the insert query fails?
  3. I haven't worked with AD for a while now but when I did I found the ADLDAP class invaluable. https://github.com/adldap/adLDAP
  4. Prepare and the bind the parameters once, before the loop. Inside the loop you only need to set the values for the params and execute. That's the idea of prepared statements - prepare once and execute many times.
  5. try // query to retrieve all 5 rows $sql = "SELECT id_number, tag_number FROM ewitti ORDER BY id_number"; $search = '1234'; // tag_number to search for $res = $db->query($sql); $num_rows = $res->num_rows; $i = 1; // Loop through the rows until $search is found while ($row = $res->fetch_assoc()) { if ($row['tag_number']==$search) { echo "Found ID: {$row['id_number']} — Record $i of $num_rows<br>"; break; } ++$i; } Output--> ID: 74 — Record 3 of 5
  6. So use a query that returns all 5 records and not just 1. Simples.
  7. I'll type slowly so you can take it in. Your ... query ... returns ... one ... row ... whose ... id ... is ... 74 ... so ... you ... will ... always ... get ... 1 ... of ... 1
  8. your query will return 1 row (that with id_number = 74) So you are trying to count from 1 to 5 when there is only 1 record Why are you testing for 74? You know that single record will have id = 74 because that is what you queried for.
  9. Then increment $current. And those array keys should be in quotes $current = 5; $next = array( 'pic1' => array('slide' => ++$current), 'pic2' => array('slide' => ++$current), 'pic3' => array('slide' => ++$current));
  10. Turn error reporting on while you are developing. There are at least four errors in that code.
  11. First, my apologies - it looks as though I accidentally clipped a couple of the lines of code when I copied from the command line screen. Here is the correct query SELECT trainer, day, bookingdate, from_time, to_time, timeslot FROM ( SELECT a.trainer , a.day , bookingdate , TIMEDIFF(start_time, IF(bookingdate=@prevdate,@prevend,open_time )) as timeslot , IF(bookingdate=@prevdate,@prevend,open_time ) as from_time , start_time as to_time , @prevend := end_time as prevend , @prevdate := bookingdate as prevdate FROM bookingavailability a JOIN (SELECT @prevend:=null,@prevdate:=null) as init INNER JOIN bookingscalendar c ON a.trainer = c.trainer AND WEEKDAY(c.bookingdate) = a.day UNION SELECT a.trainer , day , bookingdate , TIMEDIFF(close_time, IFNULL(MAX(end_time),open_time) ) as timeslot , IFNULL(MAX(end_time),open_time) as from_time , close_time as to_time , null as prevend , null as prevdate FROM bookingavailability a LEFT JOIN bookingscalendar c ON a.trainer = c.trainer AND WEEKDAY(c.bookingdate) = a.day GROUP BY a.trainer,day,bookingdate ) as gaps WHERE timeslot > '00:00:00' ORDER BY trainer, day, bookingdate, from_time; @prevdate and @prevend are user variables that used to store values from each row in the resultset so they can be used in the following row. eg in row 1 store the end_time of the booking in @prevend. (line 10) In row2 the available gap between @prevend and the start_time of this booking is calculated (line 7) However, if the second record is not the same date as the first then the available gap is the time between the start of day (open_time) and the start_time of the booking. Therefore the date of each record is stored in @prevdate (line 11). , TIMEDIFF(start_time, IF(bookingdate=@prevdate,@prevend,open_time )) as timeslot , IF(bookingdate=@prevdate,@prevend,open_time ) as from_time Similarly in the second part (line 23), if there are no bookings for the day the available time at the end of the day is close_time minus open_time instead of the end_time of last booking minus close_time , TIMEDIFF(close_time, IFNULL(MAX(end_time),open_time) ) as timeslot
  12. You can do it with a minimal resource availability table but the difficulty lies with finding the times that are not there (ie the gaps between the bookings) So if you have a bookings table mysql> SELECT * FROM bookingscalendar -> ORDER BY bookingdate, start_time; +----+-------------+---------+------------+----------+-------------+ | id | bookingdate | trainer | start_time | end_time | customer_id | +----+-------------+---------+------------+----------+-------------+ | 1 | 2014-08-18 | 1 | 10:00:00 | 11:00:00 | 101 | | 2 | 2014-08-18 | 1 | 13:00:00 | 14:30:00 | 102 | | 3 | 2014-08-18 | 1 | 16:00:00 | 17:30:00 | 103 | | 8 | 2014-08-19 | 1 | 09:00:00 | 10:30:00 | 106 | | 4 | 2014-08-20 | 1 | 09:00:00 | 11:00:00 | 101 | | 5 | 2014-08-20 | 1 | 12:00:00 | 13:00:00 | 105 | | 6 | 2014-08-20 | 1 | 15:00:00 | 17:00:00 | 106 | | 7 | 2014-08-21 | 1 | 10:00:00 | 11:00:00 | 102 | +----+-------------+---------+------------+----------+-------------+ and a table for the trainer availability by day of the week (0 = Monday) mysql> SELECT * FROM bookingavailability; +-----------------+---------+------+-----------+------------+ | availability_id | trainer | day | open_time | close_time | +-----------------+---------+------+-----------+------------+ | 3 | 1 | 0 | 09:00:00 | 20:00:00 | | 4 | 1 | 1 | 09:00:00 | 17:00:00 | | 5 | 1 | 2 | 09:00:00 | 17:00:00 | | 6 | 1 | 3 | 08:00:00 | 13:00:00 | +-----------------+---------+------+-----------+------------+ you can now find those gaps. The first part of the query finds the time difference between a booking start_time and the end_time of the previous booking (or since the start of day if no previous booking that day). The second part of the query finds any gaps between the end of the last booking and that day's closing time. mysql> SELECT trainer, day, bookingdate, from_time, to_time, timeslo -> FROM -> ( -> SELECT a.trainer -> , a.day -> , bookingdate -> , TIMEDIFF(start_time, IF(bookingdate=@prevdate,@prevend, as timeslot -> , IF(bookingdate=@prevdate,@prevend,open_time ) as from_t -> , start_time as to_time -> , @prevend := end_time as prevend -> , @prevdate := bookingdate as prevdate -> FROM bookingavailability a -> JOIN (SELECT @prevend:=null,@prevdate:=null) as init -> INNER JOIN bookingscalendar c -> ON a.trainer = c.trainer -> AND WEEKDAY(c.bookingdate) = a.day -> -> UNION -> -> SELECT a.trainer -> , day -> , bookingdate -> , TIMEDIFF(close_time, IFNULL(MAX(end_time),open_time) ) -> , IFNULL(MAX(end_time),open_time) as from_time -> , close_time as to_time -> , null as prevend -> , null as prevdate -> FROM bookingavailability a -> LEFT JOIN bookingscalendar c -> ON a.trainer = c.trainer -> AND WEEKDAY(c.bookingdate) = a.day -> GROUP BY a.trainer,day,bookingdate -> ) as gaps -> WHERE timeslot > '00:00:00' -> ORDER BY trainer, day, bookingdate, from_time; +---------+------+-------------+-----------+----------+----------+ | trainer | day | bookingdate | from_time | to_time | timeslot | +---------+------+-------------+-----------+----------+----------+ | 1 | 0 | 2014-08-18 | 09:00:00 | 10:00:00 | 01:00:00 | | 1 | 0 | 2014-08-18 | 11:00:00 | 13:00:00 | 02:00:00 | | 1 | 0 | 2014-08-18 | 14:30:00 | 16:00:00 | 01:30:00 | | 1 | 0 | 2014-08-18 | 17:30:00 | 20:00:00 | 02:30:00 | | 1 | 1 | 2014-08-19 | 10:30:00 | 17:00:00 | 06:30:00 | | 1 | 2 | 2014-08-20 | 11:00:00 | 12:00:00 | 01:00:00 | | 1 | 2 | 2014-08-20 | 13:00:00 | 15:00:00 | 02:00:00 | | 1 | 3 | 2014-08-21 | 08:00:00 | 10:00:00 | 02:00:00 | | 1 | 3 | 2014-08-21 | 11:00:00 | 13:00:00 | 02:00:00 | +---------+------+-------------+-----------+----------+----------+
  13. Or maybe something like this? <!DOCTYPE html> <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> function logEmail(name) { var dt = new Date(); var date = dt.toLocaleDateString(); var time = dt.toLocaleTimeString(); $("#ta").append("Email sent at "+date+" "+time+" to "+name+"\n" ); } $().ready(function(){ $(".mail").click(function(){ logEmail($(this).html()); }) }) </script> </head> <body> Mail: <a id='mail1' class='mail' href="mailto:john.doe@gmail.com">John Doe</a><br> Mail: <a id='mail2' class='mail' href="mailto:jane.doe@gmail.com">Jane Doe</a><br> <textarea id='ta' cols='60' rows='5'></textarea> </body> </html>
  14. Obviously code that does whatever you want to do in the event that the user has clicked on the image (ie $_GET['start_x'] is set)
  15. As I said, the test for $_GET['start_x] needs to go at the top of the page where you are currently getting info sent to the page, prior to querying the db
  16. When you click the image the page is reloaded as the form action, by default, is to call itself. It is when the page reloads that $_GET['start'] exists (not inside your while() loop) On this second load there is no username or password so nothing is retrieved from the db and you go the else{} condition. You need to test $_GET['start'] at the top of the code. edit: (Actually start_x and start_y are sent where x,y is the position of the click in the image)
  17. try UPDATE cc INNER JOIN countries USING (cn) SET cc.alpha2 = countries.alpha_2
  18. 1. Strings have a sort order, just as numbers do. ABC is less than ACB So if you sort the list ACB ABC in your function if $a = 'ACB' and $b = 'ABC' $a is greater than $b so return +1 ie $a sorts below $b in the output list ABC ($b) ACB ($a)
  19. requinix, I hate to say this but you win I too became curious so I set up a benchmark with and without an index on the date field /******* THE TABLE ********************************** CREATE TABLE `dates` ( `thedate` date NOT NULL DEFAULT '0000-00-00', `id` int(10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), KEY `idx_date` (`thedate`) ) ******************************************************/ $years = range(1986,2014); $days = range(1,365); shuffle($years); shuffle($days); /**** CREATE 10,000+ recs in random order ************ $sql = "INSERT INTO dates (thedate) VALUES (STR_TO_DATE(?, '%Y %j'))"; $stmt = $db->prepare($sql) or die($db->error); $stmt->bind_param('s', $date); foreach ($days as $d) { foreach ($years as $y) { $date = "$y $d"; $stmt->execute(); } } *******************************************************/ // BENCHMARK TEST $t1 = microtime(1); foreach ($years as $y) { $sql = "SELECT * FROM dates WHERE YEAR(thedate) = $y"; $db->query($sql); } $t2 = microtime(1); foreach ($years as $y) { $sql = "SELECT * FROM dates WHERE thedate BETWEEN '{$y}-01-01' AND '{$y}-12-31'"; $db->query($sql); } $t3 = microtime(1); echo "<h3>Result</h3><pre>"; printf ("YEAR() : %8.4f\n", $t2-$t1); printf ("BETWEEN : %8.4f\n", $t3-$t2); The results were with index on thedate YEAR() : 0.1619 BETWEEN : 0.0276 without index YEAR() : 0.1740 BETWEEN : 0.1659
  20. Use the YEAR() function ... YEAR(race_date) = $race_year
  21. I think they are part of the same person as Borrowed has just replied to Eyore's post to say it is now fixed
  22. Perhaps an example will help. I have an array of products and prices and I want them in ascending order of price but those with zero price should be listed at the end. $data = array ( array ('prodcode' => 'A123', 'price' => 10), array ('prodcode' => 'E123', 'price' => 0), array ('prodcode' => 'D123', 'price' => 40), array ('prodcode' => 'C123', 'price' => 30), array ('prodcode' => 'E124', 'price' => 0), array ('prodcode' => 'B123', 'price' => 20) ); uasort ($data, 'mysort'); function mysort ($a, $b) { if ($a['price']==0) return 1; // $a should sort below $b elseif ($b['price']==0) return -1; // $a should sort above $b else return ($a['price'] - $b['price']); // $a sorts above $b if $a < $b } foreach ($data as $p) { echo "{$p['prodcode']} {$p['price']}<br>"; } /* OUTPUT: A123 10 B123 20 C123 30 D123 40 E124 0 E123 0 */
  23. "Sort above" means "comes before" in the sorted output list. you could try using "if ($a > $b)"
  24. Yes. Where you have a many-to-many relationship (eg one plant has many compounds and one compound can come from many plants) then you need an intermediate table to associate the records +------------+ +------------------+ | plant | | compound | +------------+ +------------------+ | plant_id |--+ +---| compound_id | | plant_name | | | | compound_name | +------------+ | | +------------------+ | | | | | +---------------------+ | | | plant_compound | | | +---------------------+ | | | id | | +---< | plant_id | | | compound_id |>-+ +---------------------+
  25. If the second must always be exactly one year after the first date then why ask the user to enter a second date? Just have them enter one date then add the year yourself for the second.
×
×
  • 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.