Jump to content

Barand

Moderators
  • Posts

    24,573
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. You need to build an array for each label. You just keep overwriting the single element each time. Try $custResArray[$row['label']][] = array('list_images'=>$row['list_images'], 'image_th'=>$row['image_th'], 'image'=>$row['image'], 'cid'=>$row['cid'], 'comment'=>$row['comment']); Note the added [] in $custResArray[$row['label']][]
  2. Sorry,
  3. Not tested UPDATE Room_users INNER JOIN Users2 u ON u.mxitid = Room_users.mxitid INNER JOIN Rooms u ON u.mxitid = Rooms.mxitid SET Room_users.User = u.Username ,Rooms.creator = u.Username Duplicating the username across three tables is destroying your database normalization. You should store it in one place only (Users) and retrieve it with a join when needed.
  4. No, it is a keyword but not reserved. Example mysql> CREATE TABLE nametest (name varchar(30)); Query OK, 0 rows affected (0.27 sec) mysql> INSERT INTO nametest VALUES ('Peter'),('Paul'),('Mary'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> SELECT name FROM nametest; +-------+ | name | +-------+ | Peter | | Paul | | Mary | +-------+ 3 rows in set (0.00 sec)
  5. Merry Christmas!
  6. ... WHERE exrdate BETWEEN LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 3 MONTH AND LAST_DAY(CURDATE())
  7. That query will get you those records with dates between "2015-09-24 16:51:43" and "2015-12-24 16:51:43". Is that what you want?
  8. What happened to your GROUP BY and ORDER BY?
  9. You will need a WHERE clause otherwise you will get all months in the table.
  10. The echo would be inside the while loop
  11. You need MySQL 5.6+ for fulltext on InnoDB
  12. Check for changes in the title value. When a new value is encountered, output the new title. pseudocode: prev = ''; while (fetch next row) { if (title != prev) { output title prev = title // reset previous value } output image }
  13. I am surprised it runs as quickly as it does given all those dependent subqueries. For every record read you perform 15+ subqueries. Get rid of those subqueries and use JOINS.
  14. Seems a pointless question but, yes, so long as you don't want to change the company name.
  15. As long as your existing id is "1" then the version you had in #3 should work. (It worked for me)
  16. This is an example of a function I use for UK holidays, but should be easily adaptable. In UK, if the holiday falls at weekend, the day-off is the following Monday. function publicHols($yr) { // CALC PUBLIC HOLS FOR $yr $hols = array(); $newyr = "$yr-01-01"; switch (date('w', strtotime($newyr))) { case 6: $newyr = "{$yr}-01-03"; break; case 0: $newyr = "{$yr}-01-02"; break; } $hols['New Year'] = array($newyr,$newyr); $easter = easter_date($yr); $hols['Easter'] = array(date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter))); $mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d'); $hols['May Day'] = array($mayday,$mayday); $sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d'); $hols['Spring Bank'] = array($sbank,$sbank); $abank = (new DateTime("last monday of august $yr"))->format('Y-m-d'); $hols['August Bank'] = array($abank,$abank); $x1 = "$yr-12-25"; $x2 = "$yr-12-26"; switch (date('w', strtotime($x1))) { case 5: $x2 = "$yr-12-28"; break; case 6: $x1 = "$yr-12-27"; $x2 = "$yr-12-28"; break; case 0: $x1 = "$yr-12-26"; $x2 = "$yr-12-27"; break; } $hols['Christmas'] = array($x1,$x2); return $hols; } function showReminders($yr) { $hols = publicHols($yr); $today = new DateTime(); $today->setTime(0,0); foreach ($hols as $h=>$dates) { $dh = new DateTime($dates[0]); $days = $dh->diff($today)->format('%a days'); if ($dh==$today) { echo "It's $h!<br>"; } elseif ($dh > $today && $days <= 7) { echo $today->format('jS F Y')." reminder, $h in $days<br>"; } } } $year = date('Y'); showReminders($year); showReminders($year+1);
  17. Yes, explode() will put the numbers into an array. sort() will put the array in ascending values. Use a foreach() loop to echo the elements in the array.
  18. If there should only ever be a single record in that table why have an auto_incrementing id why even attempt to insert a new record? Just update the existing one
  19. So what are the ids of the records now in your table?
  20. Did you already have a record with an id of "1"? The id would be the id of the record to be updated, not 1 every time.
  21. You aren't inserting the id into the new record so you are not attempting to create a duplicate
  22. Here's the model I forgot to attach
  23. Your date format is invalid for storing in a database table, it needs converting to YYYY-mm-DD. Numeric values cannot contain "£".
  24. Whenever you have column names like room_type_1, room_type_2, ..., room_type_N, the database design is wrong. Database tables are not spreadsheets. You should normalize the data so each of those room_type values is in a row of its own. (See attached model.). Don't use SELECT *. Specify just the column you need. Use explicit join syntax instead of putting the join conditions in the WHERE clause. Using the attached model, the query you want would be SELECT h.hotel_num , h.name , SUM(hi.qty) as rooms FROM hotel h INNER JOIN event_hotels eh ON h.hotel_num = eh.hotel_num INNER JOIN hotels_inventory hi ON h.hotel_num = hi.hotel_num WHERE eh.event_num = 78 AND hi.inv_date BETWEEN '2015-12-01' and '2015-12-31' GROUP BY h.hotel_num ORDER BY rooms DESC;
  25. You can calculate the distance in the query and then ORDER BY distance
×
×
  • 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.