Jump to content

Barand

Moderators
  • Posts

    24,604
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Barand

    trim

    You also need to pass the first argument to __invoke() by reference otherwise the callback works but on a copy of the array. class Trim { public function __invoke(&$data, $dummy, $character_mask = null) { if (is_array($data)) { array_walk_recursive($data, array($this, '__invoke'),$character_mask); } else { $data = trim($data, $character_mask); } return $data; } } $string = 'this a test .'; $array = array('this is a string .', ' test two'); $trim = new Trim; $string = $trim($string, null, 't'); $array = $trim($array, null, 't'); echo '<pre>'.$string; print_r($array); echo trim('yesssss', 's'); /* OUTPUTS his a test . Array ( [0] => his is a string . [1] => test two ) ye */
  2. I'm sure you meant id BETWEEN $start AND $start+$count-1
  3. Because if the data comes from a database the technique used for paginating your data will be different from that used if it comes from a text or xml file.
  4. If you do that you won't know about the clients that are double-booked to inform them and change their bookings, you just hide the problem. This query will pull any booking where a room is booked at the same time as another booking. SELECT id ,bookingdate ,room ,start_time ,end_time ,trainer ,customer_id FROM bookingscalendar WHERE id IN ( SELECT b1.id FROM bookingscalendar b1 INNER JOIN bookingscalendar b2 ON b1.bookingdate = b2.bookingdate AND b1.room = b2.room AND b1.start_time < b2.end_time AND b1.end_time > b2.start_time AND b1.id <> b2.id ) ORDER BY bookingdate,room,start_time; Ensure at the time of booking that only free rooms can be allocated.
  5. And you still haven't told us where the articles are coming from. I guess you don't want help after all.
  6. We still need to see code. We have no idea where the articles are coming from.
  7. Your availability is for trainer 2, your bookings for trainer 1. Dates will be null when no matching bookings for a trainer
  8. I notice you have added another level of complexity with the inclusion of the "room" in the bookings. So as well as checking for trainer availability you also have to check for room availability.
  9. These are my table definitions CREATE TABLE `bookingscalendar` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bookingdate` date DEFAULT NULL, `trainer` int(11) DEFAULT NULL, `start_time` time DEFAULT NULL, `end_time` time DEFAULT NULL, `customer_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `bookingavailability` ( `availability_id` int(11) NOT NULL AUTO_INCREMENT, `trainer` int(11) DEFAULT NULL, `dayofweek` int(11) DEFAULT NULL, `open_time` time DEFAULT NULL, `close_time` time DEFAULT NULL, PRIMARY KEY (`availability_id`) )
  10. Or you can use PHP gd library to zoom images. This will give a x2 zoom to the area clicked in the image imagezoom.html imagezoom.php
  11. Booking date looks OK when I run it. I had to comment out the trainername column, that should be in a trainer table, not in availability table) mysql> SELECT trainer -> -- , trainername -> , dayofweek -> , bookingdate -> , CONCAT(from_time,'') as from_time -> , to_time, timeslot -> FROM -> ( -> SELECT a.trainer -> -- , a.trainername -> , dayofweek -> , 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.dayofweek -> -> UNION -> -> SELECT a.trainer -> -- , a.trainername -> , dayofweek -> , 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.dayofweek -> GROUP BY a.trainer,dayofweek,bookingdate -> ) as gaps -> WHERE timeslot > '00:00:00' -> ORDER BY trainer, dayofweek, bookingdate, from_time; +---------+-----------+-------------+-----------+----------+----------+ | trainer | dayofweek | 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 | +---------+-----------+-------------+-----------+----------+----------+ Check your data
  12. When you say "zoom" do you want to show part of the image enlarged or just enlarge the whole image like this <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> var zoom = 0; $().ready(function() { $("#pic").click(function() { if (zoom==1) { $(this).attr({"width":200,"height":200}); zoom = 0; } else { $(this).attr({"width":400,"height":400}); zoom = 1; } }) }) </script> </head> <body> <img id='pic' src="myimage.jpg" border="0" width="200" height="200"> </body> </html>
  13. Add "LIMIT 50" to the end of the query
  14. If you give the count an alias, say 'total', then you can reference that eg echo $row['total']; and also order by the total too SELECT t2.PlayerName , COUNT(t1.ID) as total FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID GROUP BY PlayerName ORDER BY total DESC
  15. Yes, he did. http://forums.phpfreaks.com/topic/296326-foreach-or-while-table-columns-and-rows/ Going around in circles with this one.
  16. If you post your code we can see what you are doing and where you are going wrong
  17. Oops. I forgot the GROUP BY SELECT t2.PlayerName , COUNT(t1.ID) FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID GROUP BY PlayerName
  18. try SELECT t2.PlayerName , COUNT(t1.ID) FROM Table2 t2 LEFT JOIN Table1 ON t2.PlayerID = t1.ID
  19. Doing it this way would require you pass just the application id (I'm guessing at the column name for the user_id in the application table) UPDATE applications a INNER JOIN users u ON a.user_id = u.id SET a.status = 2, u.verifypend = 0, u.verified = 1 WHERE a.id = :appid ;
  20. Alternatively, you could use an ENUM type column CREATE TABLE `users` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(45) DEFAULT NULL, `status` enum('yes','no','maybe') NOT NULL DEFAULT 'no', PRIMARY KEY (`id`) ) ; INSERT INTO users (username,status) VALUES ('Peter', 1), ('Paul', 3), ('Mary', 2); Then when you select mysql> SELECT * FROM users; +----+----------+--------+ | id | username | status | +----+----------+--------+ | 1 | Peter | yes | | 2 | Paul | maybe | | 3 | Mary | no | +----+----------+--------+
  21. SELECT CASE colname WHEN 1 THEN 'Yes' WHEN 2 THEN 'No' ELSE 'Maybe' END as Selection FROM tablename
  22. A single joined query should do it SELECT author , osid , type , postdate FROM friends f INNER JOIN statuses s ON f.user2_id = s.user_id ORDER BY author
  23. Don't use a for() loop, use foreach() foreach ($_SESSION['cart'] as $id => $item) { echo "<table><tr>" . "<td>" . $id. "</td>" . "<td>" . $item->getName() . "</td>" . "<td><a href=\"index1.php?delinfo=" . $id . ">Delete </a></td>" . "</tr></table"; }
  24. If you stored them as I suggested, the index of each cart item in the array would be its id. To see if it already exists $item = new Item($result->id, $result->name); if (isset($_SESSION['cart'][$result->id]) { echo "Item already exists in cart"; } Unfortunalely, as soon as you do this $cart = array_values($cart); $_SESSION['cart'] = $cart; you lose the id keys that you assigned so you can't find them anymore.
  25. You are inserting a record into the drive_routes table. That table has a column called "start" Therefore it is trying to put something into that column. As you haven't specified what to put in there it will try to put NULL. But you have said it is not allowed to be null, hence the error. So, as I have said, give a value when you insert, or define a default value. Sorry but I don't know how to say it any clearer than that.
×
×
  • 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.