Jump to content

Barand

Moderators
  • Posts

    24,604
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. This may seem an outrageous suggestion but one could always preview and check for typos before hitting the button
  2. You could try proximity searches SELECT a.hotelname as hotela , b.hotelname as hotelb FROM hotel a JOIN hotel b ON a.hotel_id <> b.hotel_id AND ABS(a.latitude-b.latitude) < 0.0001 AND ABS(a.longitude-b.longitude) < 0.0001
  3. Barand

    Limit 1

    If user_id is indexed I suspect it makes very little difference. OTOH, if it isn't indexed and the whole table would require scanning, then there may be an advantage in the LIMIT 1 depending on the target record's position in the table.
  4. SELECT topic_name , image_name FROM topic t LEFT JOIN image i ON i.tid = t.id I used LEFT join in case some topics have no image. If all topics have an image, use INNER JOIN, it's more efficient.
  5. Barand

    MYSQLI & PDO

    Yes. It really means "The MySQL extension is deprecated and has been removed: use mysqli or PDO instead."
  6. You should not store data in databases as spreadsheets. You should normalize the data and use the database correctly. So, instead of table1 +--------+------------+-------+-------+-- --+-------+ | recid | other data | MON1 | MON2 | ... | MON50 | +--------+------------+-------+-------+-- --+-------+ | 123 | XYZ1234 | aaa | bbb | ... | ccc | +--------+------------+-------+-------+-- --+-------+ you should have table1 +--------+------------+ | recid | other data | +--------+------------+ | 123 | XYZ1234 | +--------+------------+ | +--------------------------------+ | | table2 +------+--------+------------+--------+ | id | recid | date | value | +------+--------+------------+--------+ | 1 | 123 | 2016-01-01 | aaa | | 2 | 123 | 2016-01-02 | bbb | | 3 | 123 | ... | ... | | 4 | 123 | 2016-01-03 | ccc | +------+--------+------------+--------+
  7. You may want to look at string comparison functions such as soundex() levenshtein() metaphone()
  8. Why have you defined :idteacher as type PARAM_STR? As soon as you update a record you call return, which immediately exits the function. You should return at the end when all updates have been done
  9. Bind the params once before the loop $stmt = $this->db->prepare("UPDATE `esmaior_ca`.`professor` SET `teacher_grupo` = :teacher_grupo WHERE `idteacher` = :idteacher"); $stmt->bindParam(':teacher_grupo', $mudaGrupo, PDO::PARAM_INT); $stmt->bindParam(':idteacher', $id, PDO::PARAM_STR); $myArray = explode(',', $idDocentes); foreach($myArray as $id){ if (!$stmt->execute()) { print_r($stmt->errorInfo()); return array('status' => 'error', 'message' => 'Opppss...no updates..'); } else { return array('status' => 'success', 'message' => 'All changes updated...'); } }
  10. That is what I thought. You are are assigning the ids to the $mudaGrupo variable and 0, 1, 2... to the ids. Instead of foreach ($myArray as $id=> $mudaGrupo) you need foreach ($myArray as $id) {
  11. You have function to which you pass a comma-delimited list (in $idDocentes) and another value in $mudaGrupo. Without showing any code, tell me what the function is supposed to do with those inputs?
  12. The intermediate array is unnecessary. $head = array("ticker", "date_dt", "open", "high", "low", "close", "wap", "os_shares", "ttq", "total_trades", "del_qty", "sales", "profit", "op_assets"); $sql = mysql_query($query); if (mysql_num_rows($sql) > 0) { $file = fopen("stock_history.csv", "w"); fputcsv($file, $head); // write header while ($list = mysql_fetch_row($sql)) { fputcsv($file, $list); // write data } fclose($file); }
  13. You should NOT be storing them with comma separators, you should be storing them as numeric types. If there are no decimals, you could use INT, Commas and any other formatting should be added on output.
  14. You need to use the DATEDIFF() function http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_datediff but the best way to do it is not to do it at all. Derived data should not be stored in your database. Calculate it when required instead of continually updating the table.
  15. That earlier post was an example. Here's another http://forums.phpfreaks.com/topic/262473-pivot-table-like-output-indefinite-rows-and-columns-from-flat-data/?do=findComment&comment=1345109 Or do you mean an example which uses your data so that I write your code for you?
  16. With my limited knowledge of your processes and data there is little help I can offer. You need sufficient common data in the two tables to be able to match one with the other so you can determine if a record is present or not.
  17. Reply #13 above demonstrates the method. Dynamic values would come from your db data.
  18. I don't know what you have on on lines 1 and 2 but suspect you may be missing ";" at end of a line.
  19. That's right. I suggest you read my first reply (#2) again and study the attached diagram. You have a search period From - To. A room is already booked if it was checked in before the end of the search period (To) AND it is checked out after the start (From) of the search period In other words, if the booking period of the room overlaps the search period.
  20. Should be. These are my reservations +----+---------+------------+------------+------+---------------------+ | id | room_id | checkin | checkout | ip | date | +----+---------+------------+------------+------+---------------------+ | 1 | 6 | 2016-03-01 | 2016-03-05 | NULL | 2016-03-10 18:08:16 | | 2 | 2 | 2016-03-02 | 2016-03-06 | NULL | 2016-03-08 15:12:34 | | 3 | 4 | 2016-03-03 | 2016-03-07 | NULL | 2016-03-10 18:08:16 | <-booked | 4 | 3 | 2016-03-06 | 2016-03-07 | NULL | 2016-03-10 18:08:16 | <-booked | 5 | 5 | 2016-03-07 | 2016-03-08 | NULL | 2016-03-08 16:07:57 | <-booked | 6 | 1 | 2016-03-08 | 2016-03-10 | NULL | 2016-03-10 18:08:16 | | 7 | 7 | 2016-03-08 | 2016-03-09 | NULL | 2016-03-08 15:12:34 | | 8 | 8 | 2016-03-09 | 2019-03-10 | NULL | 2016-03-08 15:12:34 | +----+---------+------------+------------+------+---------------------+ If I want to check in on the 6th and out on the 8th then the rooms indicated are already booked (rooms 3, 4 and 5) SELECT * FROM rooms WHERE room_id NOT IN ( SELECT room_id FROM reservations WHERE checkin < '2016-03-08' AND checkout > '2016-03-06' ); +---------+-----------+-------------+---------------+-------------+ | room_id | room_name | room_number | room_capacity | room_status | +---------+-----------+-------------+---------------+-------------+ | 1 | Deluxe | 101 | 2 | 1 | | 2 | Standard | 102 | 2 | 2 | rooms 3,4,5 | 6 | Executive | 203 | 1 | 1 | not available | 7 | Executive | 301 | 2 | 2 | | 8 | Standard | 302 | 2 | 3 | | 9 | Executive | 303 | 1 | 3 | | 10 | Suite | 401 | 6 | 5 | | 11 | Suite | 501 | 4 | 2 | +---------+-----------+-------------+---------------+-------------+
  21. No - it is occupied from 12th to 15th. It becomes available from the 15th
  22. OK, once again I had Sn < To AND En > From You have Sn < From AND En > To Can you spot the difference yet?
  23. I was thinking you could match on idtimetable but I notice it is autoincrement in both tables and not a foreign key, so that is out of the question. Plus you have no dates to match on. Sorry but I cannot see any obvious way that your data structure supports the processing that you require.
  24. you are still making exactly the same mistake
×
×
  • 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.