Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Am I right in my assumption that you are selecting as single field EG SELECT name FROM tablename; If, say, there are five rows then, instead of this +--------+ | name 1 | +--------+ | name 2 | +--------+ | name 3 | +--------+ | name 4 | +--------+ | name 5 | +--------+ you want +--------+--------+ | name 1 | name 2 | +--------+--------+ | name 3 | name 4 | +--------+--------+ | name 5 | +-----------------+ If so, I'd use array_chunk to put the data in pairs $sql = "SELECT CONCAT(fname,' ',lname) as name FROM pupil"; $res = $pdo->query($sql) ; $data = array_chunk($res->fetchAll(), 2); echo "<table border='1'>"; foreach ($data as $row) { echo "<tr>"; if (count($row)==2) { foreach ($row as $n) echo "<td>{$n['name']}</td>"; } else echo "<td colspan='2'>{$row[0]['name']}</td>"; echo "</tr>\n"; } echo "</table>";
  2. As it clearly states at the top of the page, "PHPFreaks.com Questions, Comments, & Suggestions" is not a help forum but a forum for comments about the site. Moving to PHP Coding Help forum. Please put you code inside [ code ] tags or use the <> button in the toolbar. And state the nature of the error, preferably the full error message. Just saying there is an error is not helpful.
  3. You will need bcmath library to do it in php $x = (37.739658 + 180) / 360; $xtile = bcmul($x, bcpow(2,3200), 0); echo $xtile; giving 1195697057310125832371140711633564800180786038375872658403318152095581962252386539444192207669999 4207959832759648879404409081079451419565470276854106090269574245270335849760856131899854524127642 7324964717602398404052293164714217486036187584311373189602241206357140904647698252514706029297316 9903133287668377476541891044796672937490793296463688346149780776864963757079645918149252840838799 6339961375594565001261410980667493879041252370996632123897458999476098059823194577935019128254436 6030860257855571048100823754022659657970273909948380147791379123616894368709592470891060276597854 8271325003793426334823472642940015323876156075156400473671902771191374590935488622949583607624016 9866685125773087182548515916284210254502245372017267188638444500873324474387826190977942219959682 1489421060559178529999373973134461270691821511678419523717048252856218976237026885921242952914162 8090268067144283996195298887019205345498122356598595705782092401101204314360135493325755304
  4. Check out the MySql manual for storage requirements http://dev.mysql.com/doc/refman/5.6/en/storage-requirements.html
  5. How can we advise on how to join unknown tables? You have given us no information about your current table table structure and column names so how can we advise on how to join them. You haven't even given your current query .
  6. A captain is just another player, so why a separate table to complicate things. Just add a flag in the player table to indicate the captain. EG +--------------+ | team | +--------------+ | team_id (PK) |---+ +----------------+ +---------------+ | teamname | | | player | | shirt | +--------------+ | +----------------+ +---------------+ | | player_id (PK) |---+ +---| shirt_id (PK) | +--<| team_id | | | | description | | playername | | | +---------------+ | captain | | | +----------------+ | +----------------+ | | | player_shirt | | | +----------------+ | +--<| player_id (PK) | | | shirt_id (PK) |>--+ +----------------+ Note, the above will allow for multiple shirts per player. If there is only ever one each then lose the player_shirt table and put the shirt_id in the player table.
  7. http://uk1.php.net/manual/en/intro.pdo.php
  8. see http://dev.mysql.com/doc/refman/5.7/en/gone-away.html
  9. 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
  10. 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'
  11. A confusing mix of JOIN syntaxes in that query. Any chance of a test dump of those three tables?
  12. 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
  13. Good idea! Do it that way then.
  14. If you get a duplicate key error , tell the user.
  15. To prevent duplicate values, put a UNIQUE index on the field. Use "ORDER BY" in the query to sort by the field.
  16. 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);
  17. or you can escape the double quotes echo "\"$foo\"";
  18. 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?
  19. 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?
  20. You need to include an email header to tell it that the content is HTML
  21. You need to call mysqli_query before you can fetch any rows
  22. Put it in code tags with decent formatting applied and someone may look at it.
  23. 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
  24. Barand

    MYSQLI & PDO

    There are no more "will be"s with version 7. It's here now.
  25. 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
×
×
  • 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.