Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. If you can't work out that my name on my posts is in exactly the same place that your name is on your posts, then I am not sure you are ready for this. Anyway, your table should look like this. no | seq | s_line_no -----+--------+------------ 32 | 1 | 315 34 | 1 | 12R 34 | 2 | 12R 34 | 3 | 12R 35 | 1 | 12R 37 | 1 | Other If the user enters more than one value then you write more than one row. Now all you need is a count of the rows where s_line_no = 12R to get the answer of 4.
  2. Normalize you data so you have the values in a single column on multiple rows and your problem goes away. Using db tables like spreadsheets is never a good idea.
  3. Barand

    sql joins

    Table and column names should not be in single quotes. I would have expected you get an error message when you ran it in phpmyadmin.
  4. Don't know what your column names are but something along these lines SELECT id, COUNT(*) as tot FROM tablename GROUP BY id
  5. Here's an example <?php $width = 140; $height = 140; $rad = 60; $dtheta = M_PI/10; $im = "<svg width=\"$width\" height=\"$height\" viewBox=\"0 0 $width $height\" >\n <rect x='1' y='1' width='$width' height='$height' fill='black' />\n <g transform='translate(70,70)'>\n <circle cx='0' cy='0' r='$rad' stroke='white' fill='none' />\n"; for ($theta=0; $theta<2*M_PI; $theta+=$dtheta) { $x = $rad*cos($theta); $y = $rad*sin($theta); $im .= "<circle cx='$x' cy='$y' r='5' fill='cyan' />\n"; } $im .= "</g></svg>\n"; echo $im; ?>
  6. 0,0 is usually at the top left corner of the image.
  7. All you need is theta. You have 20 objects so theta will start at zero and increase by 2*PI/20 for each one. Then, as in the diagram, if the circle has radius R and its centre is at cx,cy the x,y coordinates for each object are x = cx + R * cos(theta) y = cy - R * sin(theta)
  8. You have already asked this same question here http://forums.phpfreaks.com/topic/300712-hoursminutes-drop-downs/?do=findComment&comment=1530668 Don't create multiple threads with the same topic. Closing this one.
  9. If you want them spaced around the circumference then the attached diagram will tell you what you need to know
  10. Would this meet your requirements?
  11. From what you have said, a lesson can have many classes and each class has many lessons. You therefore have a many-to-many relationship between class and lesson. This would be resolved by using another table to link the two. In this case I suggest it could be a "timetable" table which schedules when each class has a lesson. (See attached model) Given a class it is then easy to find the students in that class. Following the links in the diagram you can find which lessons a student has.
  12. Not sure we have the full picture yet Can a student belong to more than one class? Can a student have more than one private lesson? Can a class have more than one one private lesson?
  13. Closing this topic as you have reposted it in another of the forums
  14. Sorry, Ian. Life's too short for this. Good luck.
  15. I am well aware that the from and to dates are passed as search parameters and are are not in the database but that doesn't mean they do not have a format. If you echo $_POST['from'] and $_POST['to'], what do they look like?
  16. my data mysql> SELECT * FROM history; +-----------+----------+--------------+-------------+ | historyid | memberid | last_payment | amount_paid | +-----------+----------+--------------+-------------+ | 1 | 1 | 2015-12-20 | 1000.00 | | 2 | 1 | 2016-01-01 | 150.00 | | 3 | 1 | 2016-01-10 | 50.00 | | 4 | 1 | 2016-02-03 | 60.00 | | 5 | 1 | 2016-02-25 | 40.00 | | 6 | 1 | 2016-05-30 | 300.00 | | 7 | 1 | 2016-06-22 | 200.00 | | 8 | 2 | 2016-01-05 | 155.00 | | 9 | 2 | 2016-02-14 | 205.00 | +-----------+----------+--------------+-------------+ mysql> SELECT * FROM quarters; +-----+ | qtr | +-----+ | 1 | | 2 | | 3 | | 4 | +-----+ the query and results - I told you to put the conditions on the history table into the ON clause, not in the WHERE clause. mysql> SELECT qtr AS Quarter, SUM(amount_paid) as Total -> FROM quarters q -> LEFT JOIN history h ON qtr = QUARTER(last_payment) -> AND YEAR(last_payment) = YEAR(CURDATE()) -> AND memberid = '1' -> GROUP BY qtr; +---------+--------+ | Quarter | Total | +---------+--------+ | 1 | 300.00 | | 2 | 500.00 | | 3 | NULL | | 4 | NULL | +---------+--------+ If you have them in the WHERE clause then the LEFT JOIN behaves as as an INNER JOIN like this mysql> SELECT qtr AS Quarter, SUM(amount_paid) as Total -> FROM quarters q -> LEFT JOIN history h ON qtr = QUARTER(last_payment) -> WHERE YEAR(last_payment) = YEAR(CURDATE()) -> AND memberid = '1' -> GROUP BY qtr; +---------+--------+ | Quarter | Total | +---------+--------+ | 1 | 300.00 | | 2 | 500.00 | +---------+--------+
  17. What format are a ) sales_month? b ) from and to dates?
  18. Add a WHERE clause to your queries
  19. Do you have a record for each quarter in the quarters table? And as you are left joining to the history table, put those conditions in the ON clause instead of the WHERE clause (ie change "WHERE" to "AND" in your query)
  20. Why are you storing numeric values formatted with commas in the first place. You should do the formatting only on final output. Also, to do this you must be storing them in character fields which wrong.
  21. Correct, it won't work in that case. But that is the nature of joins. If you join one record with two matching records then the data from the one goes into both resulting records.
  22. SELECT DISTINCT Courses.CourseTitle ...
  23. You can use sql's STR_TO_DATE() function. Concatenate "-01" to the end first so you don't get day 0. Example CREATE TABLE `test_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `str_date` varchar(20) DEFAULT NULL, `date` date DEFAULT NULL, PRIMARY KEY (`id`) ) mysql> SELECT * FROM test_date; +----+----------+------+ | id | str_date | date | +----+----------+------+ | 1 | 16-Jan | NULL | | 2 | 16-Feb | NULL | | 3 | 16-Mar | NULL | +----+----------+------+ UPDATE test_date SET date = STR_TO_DATE(CONCAT(str_date, '-01'), '%y-%b-%d'); mysql> SELECT * FROM test_date; +----+----------+------------+ | id | str_date | date | +----+----------+------------+ | 1 | 16-Jan | 2016-01-01 | | 2 | 16-Feb | 2016-02-01 | | 3 | 16-Mar | 2016-03-01 | +----+----------+------------+
  24. Use AND instead of OR. Alternatively, ... WHERE idsala NOT IN (23,24,39)
  25. You need to join twice to teamlookup using different aliases INNER JOIN `teamlookup` AS tlh ON tg.home = tlh.websitedb INNER JOIN `teamlookup` AS tla ON tg.away= tla.websitedb
×
×
  • 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.