Jump to content

Barand

Moderators
  • Posts

    24,565
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I'lll state my assumptions 1 ) The data looks like this prs_o prs_op prs_pr +------+-----------+ +-------+---------+ +-------+----------+------------+--------------+ | o_id | o_name | | op_id | op_o_id | | pr_Id | pr_op_id | pr_ptd_id | pr_ip2ptd_id | +------+-----------+ +-------+---------+ +-------+----------+------------+--------------+ | 1 | Company A | | 1 | 1 | | 1 | 1 | 641 | NULL | | 2 | Company B | | 2 | 1 | | 2 | 2 | 641 | NULL | | 3 | Company C | | 3 | 1 | | 3 | 3 | NULL | 1101 | +------+-----------+ | 4 | 1 | | 4 | 4 | NULL | 1101 | | 5 | 2 | | 5 | 5 | NULL | 1101 | | 6 | 2 | | 6 | 6 | NULL | 1101 | | 7 | 2 | | 7 | 7 | NULL | 1101 | | 8 | 3 | | 8 | 8 | NULL | 1101 | | 9 | 3 | | 9 | 9 | NULL | 1101 | | 10 | 3 | | 10 | 10 | NULL | 1101 | | 11 | 3 | | 11 | 11 | NULL | 1101 | | 12 | 3 | | 12 | 12 | 641 | NULL | | 13 | 3 | | 13 | 13 | 641 | NULL | +-------+---------+ +-------+----------+------------+--------------+ 2 ) The table and join structure looks like this +--------------+ +--------------+ +--------------+ | prs_o | | prs_op | | prs_pr | +--------------+ +--------------+ +--------------+ | o_id |-----\ | op_id |------\ | pr_id | | o_name | \---<| op_o_id | \-----<| pr_op_id | +--------------+ +--------------+ | pr_ptd_id | | pr_ip2ptdid | +--------------+ Query SELECT o_id , o_name , SUM(pr_ptd_id = 641) as Tot641 , SUM(pr_ip2ptd_id = 1101) as Tot1101 FROM prs_pr pr JOIN prs_op op ON pr.pr_op_id = op.op_id JOIN prs_o o ON op.op_o_id = o.o_id GROUP BY o.o_id; Results +------+-----------+--------+---------+ | o_id | o_name | Tot641 | Tot1101 | +------+-----------+--------+---------+ | 1 | Company A | 2 | 2 | | 2 | Company B | | 3 | | 3 | Company C | 2 | 4 | +------+-----------+--------+---------+
  2. That is precisely the problem I hve been having - there is no "pr_o_id" in the structure you gave me ...
  3. Sorry, but with those typos I don't know which ones are correct and which aren't. ( therefore which columns should really be used for the join betwen prs_op and prs_pr). All those op_id and o_id names are confusing. I don't know if you really mean o_id when you say op_id or vice versa.
  4. As any suggested changes could be inferred to be criticisms of your code, you have effectively gagged us and painted yourself into a corner as far as getting help is concerned. Also, and this is a criticism of the post, not the code, you have told us or shown us what you are trying to do when a link is clicked.
  5. A dump of the structure and test data would have benn appreciated. Now, having created the tables from the structures you provided and then having entered the data manually from that useless picture of the data, I now find that when I run your queries, some of the column names in your structures do not match those used in your queries. Aaaaargh! I am rapidly losing patience with this problem. It may take longer than expected. Much longer
  6. Any chance of table structures and some test data? (Saves a job at this end.)
  7. Example // Put placeholders in the query instead of values $stmt = $con->prepare("INSERT INTO user (username, firstname, lastname) VALUES (?, ?, ?) "); // Bind the value parameter to the placeholders $stmt->bind_param('sss', $username, $fname, $lname); // Execute the query $stmt->execute(); https://www.php.net/manual/en/mysqli.prepare.php
  8. It looks like you are inserting a space at the start of your image name. Use prepared statements.
  9. The only difference that missing </div> makes is that the second find() returns the text up to the next </div>, thus giving $name = "Name: madac" $age = "Age: 18 <div class='man'>Class: 12</div> " $cls = "Class: 12" So you just need to look for and trim off the excess "<div> ... </div>" Perhaps... $html = str_get_html('<div> <div class="man">Name: madac</div> <div class="man">Age: 18 <div class="man">Class: 12</div> </div>'); $name = trim_html($html->find('div[class="man"]', 0)->innertext); $age = trim_html($html->find('div[class="man"]', 1)->innertext); $cls = trim_html($html->find('div[class="man"]', 2)->innertext); function trim_html($str) { if ( ($p = strpos($str, '<')) !== false) { $str = substr($str, 0, $p); } return trim($str); }
  10. No need to shout. It must be in your config file (but we can't possibly know that)
  11. I would expect to mysqldump mentioned somewhere in the code, not just the path where it resides.
  12. ...except when you use get? I am not "laravel literate" but aren't these using "get"? ...
  13. Before you can use $_SESSION you must call "session_start()". Put it at the start of the code.
  14. There is a very easy way to do this using a MySql myisam table. Store each vote in a table like this... CREATE TABLE `vote` ( `username` varchar(50) NOT NULL, `vote_year` year(4) NOT NULL, `week_num` tinyint(4) NOT NULL, `vote_count` int(11) NOT NULL AUTO_INCREMENT, `time_voted` datetime DEFAULT CURRENT_TIMESTAMP, `voted_for` int(11) DEFAULT NULL COMMENT 'Who/whatever was voted for', PRIMARY KEY (`username`,`vote_year`,`week_num`,`vote_count`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Note the last column of the primary key is the auto-increment column "vote_count". This will make the vote count start again at 1 for each username each week whe you add votes. mysql> INSERT INTO vote (username, vote_year, week_num, voted_for) VALUES -> ('user1', year(curdate()), weekofyear(curdate()), 1), -> ('user1', year(curdate()), weekofyear(curdate()), 20), -> ('user1', year(curdate()), weekofyear(curdate()), 5), -> ('user2', year(curdate()), weekofyear(curdate()), 5), -> ('user2', year(curdate()), weekofyear(curdate()), 1), -> ('user2', year(curdate()), weekofyear(curdate()), 3); Query OK, 6 rows affected (0.00 sec) mysql> select * from vote; +----------+-----------+----------+------------+---------------------+-----------+ | username | vote_year | week_num | vote_count | time_voted | voted_for | +----------+-----------+----------+------------+---------------------+-----------+ | user1 | 2021 | 24 | 1 | 2021-06-16 17:37:56 | 1 | | user1 | 2021 | 24 | 2 | 2021-06-16 17:37:56 | 20 | | user1 | 2021 | 24 | 3 | 2021-06-16 17:37:56 | 5 | | user2 | 2021 | 24 | 1 | 2021-06-16 17:37:56 | 5 | | user2 | 2021 | 24 | 2 | 2021-06-16 17:37:56 | 1 | | user2 | 2021 | 24 | 3 | 2021-06-16 17:37:56 | 3 | +----------+-----------+----------+------------+---------------------+-----------+ 6 rows in set (0.00 sec) To do the insert in PHP $stmt = $pdo->prepare("INSERT INTO vote (username, vote_year, week_num, voted_for) VALUES ( ?, year(curdate()), weekofyear(curdate()), ? ) "); $stmt->execute( [ $username, $votedFor ] ); Now it doesn't matter how many times a user votes. When you come to counting the votes for each "voted_for" just ignore all records whose vote_count is > 10 SELECT voted_for , count(*) as votes FROM vote WHERE vote_count <= 10 GROUP BY voted_for ORDER BY votes DESC
  15. https://www.letmegooglethat.com/?q=install+mysql+on+linux
  16. You need to install MySql on your Linux system.
  17. Your site would be "localhost". EG http://localhost/login.php or http://aaa.bbb.ccc.ddd/login.php where aaa.bbb.ccc.ddd is your IP address, though I don't don''t know if it will work for your friends - never tried it. There is free site hosting available, but you get what you pay for!
  18. Mac editors
  19. Won't the file system let you rename files?
  20. Why don't you just rename "login.html" as "login.php".
  21. A .php file can contain HTML A .html file cannot contiain php (and process it)
  22. When you call check_errors() from within your functions you are passing the local error array that was created inside the function and not the main error array in which you want to accumulate all errors. So it just accumulates them in that local array and they get lost when the function finishes.
  23. Here you go... CREATE TABLE `category` ( `id` int(11) NOT NULL, `name` varchar(45) DEFAULT NULL, `parent` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `category` -- INSERT INTO `category` VALUES (1,'happy',0), (2,'comet',1), (3,'grumpy',0), (4,'prancer',3), (5,'bashful',0), (6,'dancer',3), (7,'doc',0), (8,'blitzen',10), (9,'dasher',7), (10,'donner',5), (11,'vixen',1), (12,'cupid',2), (13,'rudolph',3); -- Dump completed on 2021-06-15 15:43:51 Make sure you you have error reporting turned on in your php.ini file. Also turn display_errors and display_startup_errors on.
  24. Is it a ,html page or a .php page? Needs to be .php to execute php code (unless server is specifically configured otherwise)
  25. Don't use "SELECT * ". Specify the columns you want. This makes it easier for others, like me, to understand what is in the table and what the query is doing. Indent your code to show the nested structure of loops etc. If you had done those I might have given this problem more than a cursory glance. So you'll have to settle for a generic example of using a recursive function to give an indented list of parent/child elements. Also, Don't run queries inside loops. Use JOINs to get all the data in a single query THE DATA TABLE: category +----+---------+--------+ | id | name | parent | +----+---------+--------+ | 1 | happy | 0 | | 2 | comet | 0 | | 3 | grumpy | 0 | | 4 | prancer | 1 | | 5 | bashful | 1 | | 6 | dancer | 2 | | 7 | doc | 2 | | 8 | blitzen | 2 | | 9 | dasher | 3 | | 10 | donner | 1 | | 11 | vixen | 1 | | 12 | cupid | 8 | +----+---------+--------+ THE OUTPUT THE CODE <?php $sql = "SELECT id, name, parent FROM category"; $res = $db->query($sql); // // store arrays of items for each parent in an array // while (list($id, $name, $parent) = $res->fetch(PDO::FETCH_NUM)) { $data[$parent][] = array('id'=>$id, 'name'=>$name); } /** * recursive function to print a category then its child categories * * @param array $arr category data * @param int $parent parent category * @param int $level hierarchy level */ function displayHierarchy(&$arr, $parent, $level=0) { if (isset($arr[$parent])) { echo "<ul>\n"; foreach($arr[$parent] as $rec) { echo "<li class='li$level'>{$rec['name']}\n"; if (isset($arr[$rec['id']])) displayHierarchy($arr, $rec['id'], $level+1); echo "</li>\n"; } echo "</ul>\n"; } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> </script> <style type="text/css"> body { font-family: verdana,sans-serif; font-size: 11pt; padding: 50px; } li { font-weight: 600;} .li0 { color: red; } .li1 { color: green; } .li2 { color: blue; } </style> </head> <body> <?php displayHierarchy($data, 0); ?> </body> </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.