Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. I suspect that is the result of putting a forum code tag in the middle of the code
  2. Setting a variable $return_value does not return the value. function get_query_value ($con,$query){ $con->real_query($query); $result=$con->use_result(); $row=$result->fetch_row(); $result->close(); return $row[0]; //<---- return the value } @ginerjm - the function is closing the result set, NOT the connection.
  3. A couple of other things. Avoid the use of "global", pass the connection to the function. You are wasting resources by using several queries, each fetching only a single column. You can do everything in a single query. function predictor ($con, $home_team, $away_team) { $sql = "SELECT IFNULL(home_team_strength * away_team_strength / home_strength, 0) as result0 , IFNULL(away_team_strength_2 * home_team_defence / away_strength, 0) as result1 FROM ( SELECT AVG(IF(home_team = ?, HTgoals, null)) as home_team_strength , AVG(IF(home_team = ?, ATgoals, null)) as home_team_defence , AVG(IF(away_team = ?, HTgoals, null)) as away_team_strength , AVG(IF(away_team = ?, ATgoals, null)) as away_team_strength_2 FROM results ) team CROSS JOIN ( SELECT AVG(HTgoals) as home_strength , AVG(ATgoals) as away_strength FROM results ) league;"; $stmt = $con->prepare($sql); $stmt->execute( [ $home_team,$home_team,$away_team,$away_team ] ); return $stmt->fetch(PDO::FETCH_NUM); }
  4. Your get_query_value() function does not return anything
  5. Use code tags and put it in a legible format, and then someone may look at the problem for you
  6. imagepng imagepng($dst, 'path/to/file');
  7. Test data mysql> select * from seizoen16; +--------------+--------+----------+----------------+--------+ | seizoen16_id | speler | gespeeld | honderdtachtig | punten | +--------------+--------+----------+----------------+--------+ | 1 | Fred | 20 | 8 | 40 | | 2 | Peter | 20 | 10 | 56 | | 3 | Paul | 22 | 15 | 63 | | 4 | Mary | 21 | 9 | 56 | +--------------+--------+----------+----------------+--------+ SELECT cast(rank as char) as rank , speler , gespeeld , honderdtachtig , punten FROM ( SELECT speler , gespeeld , honderdtachtig , @row :=@row+1 as row , @rank := IF(punten = @lastpunten, @rank, @row) as rank , @lastpunten := punten as punten FROM seizoen16 JOIN (SELECT @row:=0, @rank:=0, @lastpunten:=0) init ORDER BY punten DESC ) points +------+--------+----------+----------------+--------+ | rank | speler | gespeeld | honderdtachtig | punten | +------+--------+----------+----------------+--------+ | 1 | Paul | 22 | 15 | 63 | | 2 | Peter | 20 | 10 | 56 | | 2 | Mary | 21 | 9 | 56 | | 4 | Fred | 20 | 8 | 40 | +------+--------+----------+----------------+--------+
  8. This should get you on your way. If your tables are like these mysql> SELECT * FROM plan; +---------+--------+------------------+ | plan_id | amount | daily_commission | +---------+--------+------------------+ | 1 | 100 | 0.70 | | 2 | 250 | 1.00 | | 3 | 500 | 1.50 | | 4 | 1000 | 2.00 | +---------+--------+------------------+ mysql> select * from user; +---------+----------+---------+-------------+--------+ | user_id | password | plan_id | referred_by | status | +---------+----------+---------+-------------+--------+ | 1 | 22222 | 1 | NULL | 1 | | 2 | 12345 | 1 | 1 | 1 | | 3 | 123sad | 1 | 2 | 1 | | 4 | asdf4f | 2 | 3 | 1 | | 5 | 321423 | 4 | 2 | 1 | +---------+----------+---------+-------------+--------+ CREATE TABLE `income` ( `inc_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `amount` decimal(8,2) DEFAULT NULL, `income_date` date NOT NULL, `income_type` char(1) NOT NULL DEFAULT 'D' COMMENT '(D)aily or (R)eferral', PRIMARY KEY (`inc_id`) ) ; A query like this one, run daily, will create the daily commission income records INSERT INTO income (user_id,income_date,amount,income_type) SELECT u.user_id , CURDATE() , p.amount * p.daily_commission / 100 , 'D' FROM user u INNER JOIN plan p USING (plan_id); To calculate the referral commissions you will need a recursive function to climb the parent tree. Here's an example $db = pdoConnect($db1); /********************************************************************* * USER TEST DATA **********************************************************************/ $referrer = '6'; $plan = 1; $password = 'secret'; /********************************************************************* * ADD USER **********************************************************************/ $pass_hash = password_hash($password, PASSWORD_BCRYPT); $usersql = "INSERT INTO user (password, plan_id, referred_by) VALUES (?,?,?)"; $userstmt = $db->prepare($usersql); $userstmt->execute( [ $pass_hash, $plan, $referrer ] ); /********************************************************************* * GET THE PLAN AMOUNT 10% COMMISSION **********************************************************************/ $plansql = "SELECT amount FROM plan WHERE plan_id = ?"; $planstmt = $db->prepare($plansql); $planstmt->execute( [$plan] ); $row = $planstmt->fetch(); $commission = $row['amount'] * 0.1; // 10% commission /********************************************************************* * ADD 10% COMMISSION TO REFERRER INCOME **********************************************************************/ $incomesql = "INSERT INTO income (user_id, amount, income_date, income_type) VALUES (?,?,CURDATE(),'R')"; $incomestmt = $db->prepare($incomesql); $incomestmt->execute( [ $referrer, $commission ] ); /********************************************************************* * ADD 5% COMMISSION TO REFERRER'S REFERRERS' INCOMEs **********************************************************************/ $refsql = "SELECT referred_by FROM user WHERE user_id = ?"; $refstmt = $db->prepare($refsql); $commission /= 2; // 5% commission addCommission ($referrer, $commission, $refstmt, $incomestmt); /********************************************************************* * RECURSIVE FUNCTION TO FIND ALL REFERRERS AND ADD COMMISSION **********************************************************************/ function addCommission ($referrer, $commission, $refstmt, $incomestmt) { $refstmt->execute( [$referrer] ); $row = $refstmt->fetch(); if ($row && $row['referred_by'] != null) { $incomestmt->execute( [ $row['referred_by'], $commission ] ); addCommission ($row['referred_by'], $commission, $refstmt, $incomestmt); } } Don't store passwords as plain text. See the use of password_hash() in the above example. You would verify the password with password_verify()
  9. My advice is to remove those amounts from the user table. The plan_amount should only be in the "plan" table, not duplicated for every user with that plan. There should be a separate "income" table (user, date, amount) to which you add a record each time commission is paid.
  10. Use forward slashes. It saves having to worry about escaping backslashes (and quotes) and it's fine on Windows as well as Linux. define('MYSQL','d:/wamp/www/');
  11. Both these will do it $serialno = strstr($filename, '_', true); // get chars before the '_' $serialno = substr($filename, 0, 4); // get first four chars
  12. And remove the quotes from 'ASC'. (As the default is ASC you don't really need it.) SELECT * FROM users ORDER BY id
  13. You might find it better to load the file into the database then use the form to edit the database
  14. To illustrate the above, if you have mysql> SELECT * FROM tbl_bookings; +------------+------+-----+--------+------------+------+--------+ | booking_id | room | day | week | session_no | user | class | +------------+------+-----+--------+------------+------+--------+ | 1 | 1 | 1 | 201640 | 1 | ABC | CLASS1 | | 2 | 1 | 1 | 201640 | 2 | DEF | CLASS2 | | 3 | 1 | 1 | 201640 | 4 | GHI | CLASS3 | | 4 | 1 | 1 | 201640 | 5 | JKL | CLASS4 | +------------+------+-----+--------+------------+------+--------+ mysql> SELECT * FROM session; +------------+----------+----------+ | session_no | starts | ends | +------------+----------+----------+ | 1 | 09:30:00 | 10:29:59 | | 2 | 10:30:00 | 11:29:59 | | 3 | 11:30:00 | 12:29:59 | | 4 | 13:30:00 | 14:29:59 | | 5 | 14:30:00 | 15:29:59 | +------------+----------+----------+ Then you can find unfilled sessions like this SELECT s.session_no , s.starts , s.ends , b.room , b.user , b.class FROM session s LEFT JOIN tbl_bookings b ON s.session_no = b.session_no AND week = '201640' AND day = 1; +------------+----------+----------+------+------+--------+ | session_no | starts | ends | room | user | class | +------------+----------+----------+------+------+--------+ | 1 | 09:30:00 | 10:29:59 | 1 | ABC | CLASS1 | | 2 | 10:30:00 | 11:29:59 | 1 | DEF | CLASS2 | | 3 | 11:30:00 | 12:29:59 | NULL | NULL | NULL | <-- unfilled session | 4 | 13:30:00 | 14:29:59 | 1 | GHI | CLASS3 | | 5 | 14:30:00 | 15:29:59 | 1 | JKL | CLASS4 | +------------+----------+----------+------+------+--------+
  15. Create you own topic. Don't just tack your question on the end of someone else's. EDIT: You have $_POST['username'] but the form field has name='name'
  16. The first thing you need to do is break up that compound period column - you have three items in there that should be in separate columns Day number (1 - 7) Week (YYYYWW) Session number You will also need a session table containing five rows, one for each session 1 - 5. Your query needs to know what should be there if it wants to show you what is missing.
  17. In your other topic I showed you how to read the files and pick out the numbers and text. However you have now changed the format of that file to make it much more difficult. You also wanted to write that file to a database table and now you want to put it in a form. When you have made up your mind exactly what you do want, let us know. After all, you don't want to waste any more of our time, do you?
  18. Not from the paltry amount of information you have given us so far
  19. If you are storing the data in a database table then you do not want to ignore the subject, you want to store it with the marks. Something like this will do it // // CREATE THE TABLE // $pdo->exec("DROP TABLE IF EXISTS mark"); $sql = "CREATE TABLE mark ( mark_id int not null auto_increment primary key, subject varchar(20), term tinyint, marks int )"; $pdo->exec($sql); // // PROCESS THE DATA // $insertSql = "INSERT INTO mark (subject, term, marks) VALUES (?,?,?)"; $stmt = $pdo->prepare($insertSql); $data = file('marks.txt',FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $subject=''; foreach ($data as $val) { if (!ctype_digit($val)) { $subject = $val; // if not a number, store subject $term = 1; // reset term number } else { $stmt->execute([$subject, $term++, $val ]); // insert record } } results: mysql> SELECT * FROM mark; +---------+-----------+------+-------+ | mark_id | subject | term | value | +---------+-----------+------+-------+ | 1 | Math | 1 | 80 | | 2 | Math | 2 | 55 | | 3 | Math | 3 | 90 | | 4 | Economics | 1 | 59 | | 5 | Economics | 2 | 22 | | 6 | Economics | 3 | 60 | | 7 | English | 1 | 83 | | 8 | English | 2 | 68 | | 9 | English | 3 | 76 | +---------+-----------+------+-------+ 9 rows in set (0.00 sec)
  20. Doesn't the week type tell you if it's week A, B or H? I still don't wee what the week name is for. Have you sample data.
  21. Week name? Do you really name your weeks? I would have expected to see a DATE field in that table, and in the mistable (booking) table too.
  22. What does "MONA:2" mean?
  23. You aren't process the array at the correct level. Add the line indicated to view the array key. You should have keys0, 1, 2, .... $this_temp_array = $results->Messages; foreach ($this_temp_array as $key => $value) { echo "Key is: $key<br>"; // <-- add this to get a clue if ($key == $n) $Message = $value; //print_r ($Message); $MessageID = $Message->Message->MessageID; $n=$n+1; echo $MessageID; }
  24. $xml = simplexml_load_string($responseXml); foreach ($xml->Messages->Message as $mes) { echo $mes->MessageID . '<br>'; }
  25. Sorry. Plan B echo "<pre>" . htmlentities($responseXml) . "</pre>";
×
×
  • 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.