Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Or just use Excel instead of trying to store spreadsheet tables in a database. I agree with @benanamen - normalize. Something like this +------------+ | employee | +------------+ +------------+ | emp_id |----+ | time | | fname | | +------------+ | lname | | | time_no |----+ | pay | +----<| emp_id | | | grade |--+ | time_emp | | +------------+ | +------------+ | | | | +------------+ | | | overtime | | | +------------+ | +------<| grade | | | time_no |>---+ | hours | +------------+ Your table data employee time overtime +--------+-------+-------+ +---------+--------+----------+ +-------+-------+---------+-------+ | emp_id | pay | grade | | time_no | emp_id | time_emp | | ot_id | grade | time_no | hours | +--------+-------+-------+ +---------+--------+----------+ +-------+-------+---------+-------+ | 11 | 12500 | 3 | | 1 | 11 | 6 | | 1 | 3 | 1 | 10 | | 15 | 15000 | 5 | | 1 | 15 | 4 | | 2 | 3 | 2 | 5 | | 23 | 17000 | 7 | | 1 | 23 | 15 | | 3 | 3 | 3 | 0 | | 67 | 20000 | 9 | | 1 | 67 | 23 | | 4 | 5 | 1 | 15 | +--------+-------+-------+ | 2 | 11 | 2 | | 5 | 5 | 2 | 10 | | 2 | 15 | 23 | | 6 | 5 | 3 | 5 | | 2 | 23 | 8 | | 7 | 7 | 1 | 20 | | 2 | 67 | 15 | | 8 | 7 | 2 | 15 | | 3 | 11 | 19 | | 9 | 7 | 3 | 10 | | 3 | 15 | 10 | | 10 | 9 | 1 | 25 | | 3 | 23 | 11 | | 11 | 9 | 2 | 20 | | 3 | 67 | 11 | | 12 | 9 | 3 | 15 | +---------+--------+----------+ +-------+-------+---------+-------+ Then SELECT e.emp_id , e.pay , t.time_no , ot.hours FROM employee e JOIN time t ON e.emp_id = t.emp_id JOIN employee e2 ON t.time_emp = e2.emp_id JOIN overtime ot ON e2.grade = ot.grade AND t.time_no = ot.time_no WHERE e.emp_id = 67 ORDER BY time_no; +--------+-------+---------+-------+ | emp_id | pay | time_no | hours | +--------+-------+---------+-------+ | 67 | 20000 | 1 | 20 | | 67 | 20000 | 2 | 10 | | 67 | 20000 | 3 | 0 | +--------+-------+---------+-------+
  2. I don't know if it's the only problem (can't see your data) but the WHERE condition should be part of the JOIN ON condition for "chat_to_users" . . . FROM chat_message AS msgs LEFT JOIN chat_to_users AS msgsTo ON msgs.chat_message_id = msgsTo.id AND msgsTo.to_user_id = 7 LEFT JOIN production_data AS orders ON msgs.order_id = orders.id ORDER BY msgs.timestamp DESC otherwise the join behaves as an INNER JOIN
  3. then test it.
  4. No. That line is trying to set $_SESSION['Role'] to the value of (apparently undefined) $role.
  5. In admin,php, where is $role being set?
  6. It is possible (and preferred) for you to show table structures without pictures DESCRIBE season; +--------------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------+------+-----+---------+-------+ | season | char(4) | NO | PRI | | | | season_start | date | YES | MUL | | | | season_end | date | YES | MUL | | | +--------------+---------+------+-----+---------+-------+ SHOW CREATE TABLE season; CREATE TABLE `season` ( `season` char(4) NOT NULL, `season_start` date DEFAULT NULL, `season_end` date DEFAULT NULL, PRIMARY KEY (`season`), KEY `idx_season_start` (`season_start`,`season_end`), KEY `idx_season_end` (`season_end`) )
  7. If you received a message from a complete stranger, would you click on the links?
  8. that was a clue.
  9. I didn't say is was right - it's just what was in the code I was condensing to illustrate the nested loops.
  10. Use explicit joins FROM A JOIN B ON ... rather than confusing the issue by putting the join conditions in a WHERE clause (less efficient too). Also there may be employee/s at the top of the management tree without a manager. With my LEFT JOIN these would still appear, with w3fools's version they would not.
  11. It really helps if you tell what "doesn't work" means, otherwise it tells us nothing. Although, glancing at that query, try this revised version $sql = "SELECT * FROM `comments` LEFT JOIN `artikelen` ON comments.nummer= artikelen.nummer AND artikelen.nummer = $articlenummer ORDER BY artikelen.nummer";
  12. Assign role to users Have an access table to define which roles can access which files (As requested, all tables are accessible via PDO) +-------------+ +---------------+ +--------------+ | user | | role | | file | +-------------+ +---------------+ +--------------+ | user_id | +------| role_id |-+ +---| file_no | | username | | | description | | | | filename | | password | | +---------------+ | | +--------------+ | role_id |>-----+ | | +-------------+ | | | +-------------+ | | | access | | | +-------------+ | +--<| role_id | | | file_no |>-+ +-------------+
  13. This summarises a section of your code ... for($j='2018';$j<=$maxdate;$j++) { $q="select id from seasonstats where date >='$session_value' and date <='$session1_value' order by date"; while($r=mysqli_fetch_object($qr)) { $q="select distinct(_player_id) from seasonteamstats where matchid in ($match_id_list) order by lastname"; while($r=mysqli_fetch_object($qr)) { foreach($players_ids as $var=>$val) { $q="select * from seasonteamstats where _player_id='$val' and matchid in ($match_id_list) order by lastname"; } } } } Do you find it takes a while to run? You need to learn to use JOINs and you can do all this in one efficient query. The golden rule is "Don't run queries inside loops"
  14. The ghost of Jacques still walks these corridors
  15. There are some options that you should set when you connect to the database server. For example, this my included connection file const HOST = 'localhost'; const USERNAME = '???'; const PASSWORD = '???'; const DATABASE = '???'; function pdoConnect($dbname=DATABASE) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } $conn = pdoConnect() will then connect to my default database, but if I set up a test database "bintech" to put your tables in for testing code, then I can call $conn = pdoConnect('bintech'). Your UPDATE statement is wrong as it will update all records for which "lockup_id = lockup_id", which is all of them. You are missing the ":"
  16. Join the table to itself SELECT emp.name as empname , boss.name as bossname FROM employee as emp LEFT JOIN employee as boss ON emp.boss_id = boss.id;
  17. I showed you how to use a prepared query, rewriting your code for you here Read the replies.
  18. Are you sure you have matching postcode values? No hidden whitespace. And records that match the lidnummer?
  19. I am wondering if the lack of primary keys in your tables is a contributing factor Set up the tables and tried it - deletion worked when run manually. mysql> insert into lid values -> (1, 'A', 'B','C','D'), -> (2, 'A', 'B','F','D'); Query OK, 2 rows affected (0.07 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> insert into postcode values -> ('C', 'aaa', 'bbb'), -> ('F', 'ccc', 'ddd'); Query OK, 2 rows affected (0.04 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> DELETE lid, postcode FROM lid INNER JOIN postcode WHERE lid.postcode = postcode.postcode AND lid.lidnummer = 2; Query OK, 2 rows affected (0.05 sec) mysql> select * from lid; +-----------+----------+------------+----------+------------+ | lidnummer | voornaam | achternaam | postcode | huisnummer | +-----------+----------+------------+----------+------------+ | 1 | A | B | C | D | +-----------+----------+------------+----------+------------+ 1 row in set (0.00 sec) mysql> select * from postcode; +----------+-------+------------+ | postcode | adres | woonplaats | +----------+-------+------------+ | C | aaa | bbb | +----------+-------+------------+ 1 row in set (0.00 sec)
  20. Can you post the structures of your "lid" and "postcode" tables for us.
  21. The purpose of using prepared statements is so you don't put values directly into the query itself. Instead you use a "placeholder" for the value and pass the value in the execute statement. $query = " SELECT * FROM task_list WHERE user_id = ? ORDER BY task_list_id DESC "; $statement = $connect->prepare($query); $statement->execute( [ $_SESSION["user_id"] ] ); There is another commonly used convention when using a database: if you want to produce a list of data items from a table then execute a query against that table. Querying the task_list table in order to get a list of lockups ain't going to work too well.
  22. foreach ($data as $name => $paid_arr) { $tdata .= "<tr><td>$name</td>"; foreach ($paid_arr as $p) { $cls = $p=='N' ? 'hilite' : ''; $tdata .= "<td class='$cls'>$p</td>"; } $tdata .= "</tr>\n"; }
  23. Give your tables meaningful names that describe the entity being stored in the table. Looking at the XML then perhaps the name would be "lockup". There is a requirement that each row in a table should have unique identifier otherwise you cannot edit/delete rows. The easiest way is use an auto_incrementing value that guarantees uniqueness. CREATE TABLE lockup ( lockup_id int not null auto_increment primary key, mediaurl varchar(60), imagename varchar(60), title varchar(60) );
  24. https://dev.mysql.com/doc/refman/5.7/en/char.html
×
×
  • 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.