Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. From what I could see, you only needed the results table for both those queries. Try SELECT Player.MembershipNo , Player.FirstName , Player.LastName, Venue.VenueName as Venue, Results.MemCard, Results.EarlyReg, Position.Points as Venue_Points, Results.Date, tot.PlayerTotal FROM Player INNER JOIN Results ON Player.MembershipNo = Results.MembershipNo INNER JOIN Venue ON Venue.VenueID = Results.VenueID INNER JOIN Position ON Results.Position = Position.Position INNER JOIN ( SELECT MembershipNo, COUNT(Date) as PlayerTotal FROM Results GROUP BY MembershipNo ) as tot ON Player.MembershipNo = tot.MembershipNo WHERE Results.Date BETWEEN '2014-01-01' AND '2015-01-01' ORDER BY MembershipNo, venue If you want player/venue totals, change the subquery to add in the venue and join on membership and venue
  2. If all you wanted to do was count the number of games for each player, what would the query be? If all you wanted to do was count the number of games for each player at each venue, what would the query be? I have to ask because I don't know what your original tables look and the structure of your database.
  3. After calling $stmt->execute(), check the value in $stmt->error
  4. I think you should step back and rethink your data model as it doesn't readily support the processes you want. You are storing derived data (not a good thing) and making that worse by relying on that derived data to join tables (hol_bal BETWEEN ....)
  5. That error usually signals an error in the query. Check value of mysql_error(). Also try swapping the " and ' around so $slug is interpreted correctly
  6. +1 As long as you stick with this
  7. I missed the "[ ]", it should have been $data[] = sprintf("('%s', '%s')", $row[1], $piece);
  8. I think you have a table missing Room -> PC = 1 to many PC ----> Software = many to many So you need another table to link the pc with the software
  9. The use of IN should work except it looks as though you have a misspelling in client_h $sql=mysql_query("SELECT * FROM routes WHERE '$client' IN(client_a, client_b, client_c, client_d, client_e, client_f, client_g, client-h) ORDER BY date DESC"); ^ | underscore?
  10. Calculate the SUM()s in a subquery SELECT a.vac, a.per, a.hol, IFNULL(tots.vac, 0.00) as vac_req, IFNULL(tots.per, 0.00) as per_req, IFNULL(tots.hol, 0.00) as hol_req, h.day, hm.ptoreq_id, hm.id as hol_map_id FROM ptoadp as a JOIN ( SELECT ee_id, SUM(vac) as vac, SUM(per) as per, SUM(hol) as hol FROM ptoreq GROUP BY ee_id ) tots USING (ee_id) JOIN holidays h ON h.hol_bal BETWEEN a.hol_cur AND a.hol AND h.expdate >= curdate() LEFT JOIN ptoreq_holiday_map hm ON h.id = hm.holiday_id LEFT JOIN ptoreq r ON a.ee_id = r.ee_id AND r.ptoreq_id = hm.ptoreq_id AND r.declined_date IS NULL AND r.enddate >= curdate() WHERE a.ee_id = 1 ORDER BY h.date; Gives +-------+------+-------+---------+---------+---------+---------+-----------+------------+ | vac | per | hol | vac_req | per_req | hol_req | day | ptoreq_id | hol_map_id | +-------+------+-------+---------+---------+---------+---------+-----------+------------+ | 23.00 | 8.00 | 72.00 | 0.00 | 0.00 | 16.00 | Test A | 2 | 2 | | 23.00 | 8.00 | 72.00 | 0.00 | 0.00 | 16.00 | Test B | NULL | NULL | | 23.00 | 8.00 | 72.00 | 0.00 | 0.00 | 16.00 | MLK Day | 1 | 1 | +-------+------+-------+---------+---------+---------+---------+-----------+------------+
  11. An unusual type of quiz where each answer has many questions. So given the answer you have to guess what the question was? The ones I've seen before have had the question id as a foreign key in the answer table.
  12. Define the primary key of the "oil_blend_with" table as PRIMARY KEY (id, name) And don't have it as a temporary table, make it permanent. That is how column 7 data should be stored. edit: Except you should be storing ids in the second table and not the names. I meant to add some code to write data in a single insert: $query = "SELECT * FROM essential_oils ORDER BY oil_name"; // Select Everything From The Table $result = mysql_query($query); while($row = mysql_fetch_row($result)) // While there is something to do, Do It! { $pieces = explode(",", $row[7]); // Split the String into each piece $data = array(); foreach ($pieces as $piece) // For each array add it to another temp table { $data = sprintf("('%s', '%s')", $row[1], $piece); // display on the screen the loop output to test. remove later echo "&nbsp&nbsp&nbsp".$row[1]."&nbsp&nbsp".ucwords($piece)."<br />"; } } $q = "INSERT INTO oil_blend_with (id, name) VALUES " . join(',', $data); $r = mysql_query($q); And as you are only interested in two fields from essential oils table, those are the only ones you should select (not "select * ")
  13. If your form method is GET you have a limit of around 2000 characters. If that is your problem change the method to POST
  14. Do not double post. You have posted that question here http://forums.phpfreaks.com/topic/285736-php-and-crystal-report/?do=findComment&comment=1466830
  15. Like all things it's a tradeoff. InnoDB gives you FKs with enforced referential integrity and transactions. MyISAM gives you extra speed on select statements and fulltext indexing. And yes, if you use a field as FK with MyISAM then index it, and also index any fields regularly used in your WHERE clauses.
  16. your credentials need to to be four separate string values $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE);
  17. http://www.php.net/manual/en/control-structures.for.php Look at "for" and "while"
  18. They should be like this mysql> SELECT * FROM table_1; +----+------+-----------+ | id | user | needed_id | +----+------+-----------+ | 1 | Bob | 2 | | 2 | Jim | 4 | +----+------+-----------+ mysql> SELECT * FROM table_2; +----+--------------+ | id | needed_value | +----+--------------+ | 1 | 0 | | 2 | 9 | | 3 | 1 | | 4 | 0 | | 5 | 2 | +----+--------------+ However, as you have it now, horrible db design calls for horrible queries SELECT a.id, a.user, a.column_needed, b.val FROM table_1 as a INNER JOIN ( SELECT 'i1' as id, i1 as val FROM table_2 UNION SELECT 'i2', i2 FROM table_2 UNION SELECT 'i3', i3 FROM table_2 UNION SELECT 'i4', i4 FROM table_2 UNION SELECT 'i5', i5 FROM table_2 ) as b ON a.column_needed = b.id +----+------+---------------+------+ | id | user | column_needed | val | +----+------+---------------+------+ | 1 | Bob | i2 | 9 | | 2 | Jim | i4 | 0 | +----+------+---------------+------+
  19. Have a try yourself first and come back when you get stuck
  20. Easiest way is to store the data in an array as you loop through the query results $data[$service][$user][] = $image Then use a couple of nested foreach loop to display the data
  21. I'll start you off with query needed. I am a bit confused by user 10 appearing twice in the output so I am assuming you want the output order by service SELECT u.int_uid , u.str_uname , s.str_sname , p.str_imagename FROM tbl_user u INNER JOIN tbl_service s USING (int_uid) INNER JOIN tbl_photos p USING (int_sid) ORDER BY s.str_sname
  22. Do you mean print "<table border=1 align=center>\n"; print "<tr align=left valign=top>"; while ($row=mysql_fetch_array($result_id)) { print "<td>$row[0]</td>\n"; } print "</tr>\n"; print "</table>\n";
  23. Does your table only contain the two columns (date, type) or is there also a key field that would group the dates together?
  24. The data mysql> SELECT * FROM equipment; +----+----------+---------+----------+ | id | name | type | equipped | +----+----------+---------+----------+ | 1 | Weapon 1 | Weapons | 0 | | 2 | Weapon 2 | Weapons | 0 | | 3 | Weapon 3 | Weapons | 1 | | 4 | Weapon 4 | Weapons | 0 | | 5 | Armour 1 | Armour | 0 | | 6 | Armour 2 | Armour | 1 | | 7 | Armour 3 | Armour | 0 | | 8 | Armour 4 | Armour | 1 | | 9 | Armour 5 | Armour | 0 | +----+----------+---------+----------+ The code $sql = "SELECT type, name, equipped FROM equipment ORDER BY type, equipped DESC, name"; $res = $db->query($sql); $curType=''; while (list($type,$name,$equip) = $res->fetch_row()) { if ($curType != $type) { echo "<h4>$type</h4>"; $curType = $type; } $eText = $equip ? '(equipped)':''; echo "$name $eText<br>"; } The results Armour Armour 2 (equipped) Armour 4 (equipped) Armour 1 Armour 3 Armour 5 Weapons Weapon 3 (equipped) Weapon 1 Weapon 2 Weapon 4
  25. Start out by deciding the various attributes that you feel are important. For example Material (wood or aluminium) Length Weight Strength Stability etc Give the attributes individual weightings according to importance. When users score the attributes, multiply the score by the weighting. You will also have to take into account the different types of ladder (step ladder, extending ladder, roof ladder etc) and the tasks they are used for, so you will probably finish up with several diferent rankings. Have fun
×
×
  • 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.