Jump to content

Barand

Moderators
  • Posts

    24,573
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. see http://dev.mysql.com/doc/refman/5.7/en/gone-away.html
  2. Escaping double quotes was shown to you back in January! Read the replies. http://forums.phpfreaks.com/topic/300694-mysql-full-text-search/?do=findComment&comment=1530578
  3. You could do this (where you enter AB21 1AB, say) SELECT Pcode , Latitude , Longitude FROM postcodes WHERE 'AB21 1AB' LIKE CONCAT(Pcode,'%') ; BUT there is a more efficient way. Put an index on Pcode (primary key?) and set its type to VARCHAR. A TEXT type can hold a novel and is overkill for 4 characters. Then, as the final part of a postcode is always 3 characters, remove those and trim off any space and search for the remaining Pcode = 'AB21'
  4. A confusing mix of JOIN syntaxes in that query. Any chance of a test dump of those three tables?
  5. you'll find answers on these two pages of the PHP manual http://uk1.php.net/manual/en/language.types.array.php http://uk1.php.net/manual/en/language.types.object.php
  6. Good idea! Do it that way then.
  7. If you get a duplicate key error , tell the user.
  8. To prevent duplicate values, put a UNIQUE index on the field. Use "ORDER BY" in the query to sort by the field.
  9. You are missing the [] after $json $json[] = array('a'=>$a, 'b'=>$b, 'c'=>$c, 'd'=>$d, 'e'=>$e, 'f'=>$f, 'g'=>$g, 'h'=>$h, 'i'=>$i);
  10. or you can escape the double quotes echo "\"$foo\"";
  11. OK, instead of phoning I keep trying online all morning until a suitable timeslot is offered to me. I have now wasted an hour of my life. Alternatively I arrive late and sit there for hours waiting for an appointment slot. This is not a great user experience. Having established which date I want and which doctor I want to see, why don't you then offer me a list of available times so I can select one that suits me?
  12. So I ring the doctor's to arrange an appointment and the next timeslot is 12:15. Unfortunately it is impossible for me to get there before 2pm. Now what happens? Do I keep ringing back until the next available slot is 2:00 then take the appointment?
  13. You need to include an email header to tell it that the content is HTML
  14. You need to call mysqli_query before you can fetch any rows
  15. Put it in code tags with decent formatting applied and someone may look at it.
  16. After some experimenting, here's another option for you but it will only work with a MyISAM table Define a multi-column primary key so that the auto_incrementing column comes last (doctor_id, date, appointment_id) CREATE TABLE `appointment` ( `appointment_id` int(11) NOT NULL AUTO_INCREMENT, `doctor_id` int(11) NOT NULL DEFAULT '0', `patient_id` varchar(45) DEFAULT NULL, `app_date` date NOT NULL DEFAULT '0000-00-00', `app_time` time DEFAULT NULL, PRIMARY KEY (`doctor_id`,`app_date`,`appointment_id`) ) ENGINE=MyISAM ; Also note I have separated date and time so the date can be used in the key without the time. So in the table I now have +----------------+-----------+------------+------------+----------+ | appointment_id | doctor_id | patient_id | app_date | app_time | +----------------+-----------+------------+------------+----------+ | 1 | 1 | 3243 | 2016-03-23 | 12:05:00 | | 2 | 1 | 9574 | 2016-03-23 | 12:15:00 | | 1 | 1 | 2174 | 2016-03-27 | 12:05:00 | | 1 | 2 | 5474 | 2016-03-24 | 14:05:00 | | 2 | 2 | 8763 | 2016-03-24 | 14:15:00 | | 1 | 2 | 5674 | 2016-03-28 | 14:05:00 | +----------------+-----------+------------+------------+----------+ If I now insert a new appointment for doctor #1 on the 23rd, the new record is created with id=3 INSERT INTO appointment (doctor_id, patient_id, app_date, app_time) VALUES (1, 9991, '2016-03-23', '15:00'); +----------------+-----------+------------+------------+----------+ | appointment_id | doctor_id | patient_id | app_date | app_time | +----------------+-----------+------------+------------+----------+ | 1 | 1 | 3243 | 2016-03-23 | 12:05:00 | | 2 | 1 | 9574 | 2016-03-23 | 12:15:00 | | 1 | 1 | 2174 | 2016-03-27 | 12:05:00 | | 1 | 2 | 5474 | 2016-03-24 | 14:05:00 | | 2 | 2 | 8763 | 2016-03-24 | 14:15:00 | | 1 | 2 | 5674 | 2016-03-28 | 14:05:00 | | 3 | 1 | 9991 | 2016-03-23 | 15:00:00 | <--- new +----------------+-----------+------------+------------+----------+ Now all that is needed is to assemble your code
  17. Barand

    MYSQLI & PDO

    There are no more "will be"s with version 7. It's here now.
  18. Normalize your data. You have info in both those those tables that doesn't belong. You should have +----------------+ +---------------------+ +-----------------+ | doctor | | appointment | | patient | +----------------+ +---------------------+ +-----------------+ | doctor_id (PK) |---+ | appointment_id (PK) | +---| patient_id (PK) | | doctorname | +----<| doctor_id (FK) | | | patientname | +----------------+ | patient_id (FK) |>---+ | address | | app_time | | mobile | +---------------------+ +-----------------+ If you want doctors with appointment dates, use a query SELECT DISTINCT d.doctor_id , doctorname , DATE(app_time) as Appointment_dates FROM appointment a INNER JOIN doctor d USING (doctor_id); +-----------+------------+-------------------+ | doctor_id | doctorname | Appointment_dates | +-----------+------------+-------------------+ | 1 | Dr A | 2016-03-23 | | 1 | Dr A | 2016-03-27 | | 2 | Dr B | 2016-03-24 | | 2 | Dr B | 2016-03-28 | +-----------+------------+-------------------+ Store dates and time using sql DATETIME types. Other formats cannot be be compared and sorted. eg mysql> SELECT * FROM appointment; +----------------+-----------+------------+---------------------+ | appointment_id | doctor_id | patient_id | app_time | +----------------+-----------+------------+---------------------+ | 1 | 1 | 3243 | 2016-03-23 12:05:00 | | 2 | 1 | 9574 | 2016-03-23 12:15:00 | | 3 | 1 | 2174 | 2016-03-27 12:05:00 | | 4 | 2 | 5474 | 2016-03-24 14:05:00 | | 5 | 2 | 8763 | 2016-03-24 14:15:00 | | 6 | 2 | 5674 | 2016-03-28 14:05:00 | +----------------+-----------+------------+---------------------+ Also, you should not store derived data and your "appointment code" is derived from data already stored and by counting the appointments each day for each doctor. Having got the required data by query you would format it as shown by requinix. Example $sql = "SELECT DATE_FORMAT(app_time, '%d-%m-%Y') as formatteddate , TIME_FORMAT(app_time, '%l:%i %p') as time , @seq := IF(@prevday=DATE(app_time) AND @prevdoc=doctor_id, @seq+1, 1) as seq , @prevdoc:=doctor_id as doctor_id , @prevday:=DATE(app_time) as date FROM ( SELECT doctor_id , app_time FROM appointment JOIN (SELECT @sequence:=0, @prevdoc:=0, @prevday:='1901-01-01') as init ORDER BY doctor_id, app_time ) apps"; $res = $pdo->query($sql); echo "<pre>\n"; echo "Doctor_id Date Seq Code\n"; foreach ($res as $row) { printf(" %d %-15s %3d DR%03d-%s-%04d\n" , $row['doctor_id'] , $row['date'] , $row['seq'] , $row['doctor_id'] , $row['formatteddate'] , $row['seq'] ); } echo "</pre>\n"; Results: Doctor_id Date Seq Code 1 2016-03-23 1 DR001-23-03-2016-0001 1 2016-03-23 2 DR001-23-03-2016-0002 1 2016-03-27 1 DR001-27-03-2016-0001 2 2016-03-24 1 DR002-24-03-2016-0001 2 2016-03-24 2 DR002-24-03-2016-0002 2 2016-03-28 1 DR002-28-03-2016-0001
  19. You need to use a UNION SELECT Year , Team , COUNT(*) as Played FROM ( SELECT Year, Away_Team as Team FROM table UNION SELECT Year, Home_Team as Team FROM table ) teams GROUP BY Year, Team
  20. This may seem an outrageous suggestion but one could always preview and check for typos before hitting the button
  21. 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
  22. 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.
  23. 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.
  24. Barand

    MYSQLI & PDO

    Yes. It really means "The MySQL extension is deprecated and has been removed: use mysqli or PDO instead."
×
×
  • 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.