Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Add another element to the $dogs array to store the COI (Fa) for that dog. It will require a recursive function along these lines function COI(ancester_id) { if (COI is in the table already) { return COI from the table } else { calculate COI of ancester // will require calls to COI(ancester) the recursive bit store in table return calculated value; } }
  2. This simple library function of mine will do it. You can use CSS styling to make it look prettier. $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "SELECT * FROM users WHERE allowed_user=1"; // call the function echo query2HTML($db, $sql); function query2HTML($db, $sql) { $output = "<table border='1' cellpadding='2' style='border-collapse:collapse'>\n"; // Query the database $result = $db->query($sql); // check for errors if (!$result) return ("$db->error <pre>$sql</pre>"); if ($result->num_rows == 0) return "No matching records"; // get the first row and display headings $row = $result->fetch_assoc(); $output .= "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n"; // display the data do { $output .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } while ($row = $result->fetch_assoc()); $output .= "</table>\n"; return $output; } I suggest you examine each line of code in conjunction with the PHP manual until you understand what each line is doing.
  3. try this version $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "SELECT id, dogname, sire, dam FROM dogtable"; $dogs = $sires = $dams = array(); $res = $db->query($sql); while (list($id, $nm, $s, $d) = $res->fetch_row()) { $dogs[$id] = [$s,$d,$nm]; } function getAncestors($id, &$dogs, &$ancests, $dist) { if ($id==0) return; $ancests[$id] = $dist; if (isset($dogs[$id]) ) { getAncestors($dogs[$id][0], $dogs, $ancests, $dist+1); getAncestors($dogs[$id][1], $dogs, $ancests, $dist+1); } } $dogid = 1; $sires = $dams = []; getAncestors($dogs[$dogid][0], $dogs, $sires, 1); getAncestors($dogs[$dogid][1], $dogs, $dams, 1); ksort($sires); ksort($dams); #echo '<pre>',print_r($dogs, true),'</pre>'; echo '<pre>sires ',print_r($sires, true),'</pre>'; echo '<pre>dams ',print_r($dams, true),'</pre>'; $common = array_intersect_key($sires,$dams); #$common = array_merge($sires,$dams); echo "<pre>"; echo "| ID | NAME | SIRE | DAM |\n"; echo "| | | DIST | DIST |\n"; echo "|-----|--------------------|------|------|\n"; foreach ($common as $id => $dist) { printf("|%4d | %-18s | %4d | %4d |\n", $id, $dogs[$id][2], $sires[$id], $dams[$id]); }
  4. Can you post/attach a dump of your data?
  5. A table name like "attendance_15_16" implies you have your attendance data spread over several separate tables. Bad design. What is the "admin" column. I would expect to see a student_id column in there to identify whose attendance it is recording. You can accomplish what you want with a single query, but it help if, first, we know the structure of your other related tables also.
  6. I suppose we have to keep telling you:
  7. Reconfgure your array so it is more useful, like Array ( [Royal London] => 35.18 [Zurich Life] => 34.18 [Friends First] => 32.74 [Aviva] => 39.13 [Irish Life] => 40.59 [New Ireland] => 35.26 ) This will do it $data = array ( array ( 35.18 , 'Royal London' ) , array ( 34.18 , 'Zurich Life' ) , array ( 32.74 , 'Friends First' ) , array ( 39.13 , 'Aviva' ) , array ( 40.59 , 'Irish Life' ) , array ( 35.26 , 'New Ireland' ) ); // reconfigure $companies = array_column($data,1); $prices = array_column($data,0); $newdata = array_combine($companies, $prices); echo $newdata['Zurich Life']; //--> 34.18
  8. That will only affect the display in the form, not convert. Lowercase characters are posted EG <?php if ($_SERVER['REQUEST_METHOD']=='POST') echo "Posted value : {$_POST['test']}"; //--> Hello World ?> <form method='post'> <input type='text' name='test' style='text-transform:uppercase' value='Hello World'> <input type='submit' name='btnsub' value='Submit'> </form>
  9. Your second code doesn't "return" the rows it just prints the array containing the rows. Is that code inside a function? If not you shouldn't be using return. If it is, how are you processing the results returned by the first code. You should not be running queries inside a loop, you should use a JOIN to get all the results in a single query call, like this SELECT p.id , p.title , p.description FROM posts as p JOIN post_members as pm ON p.id = pm.post_id WHERE pm.userid = :userid
  10. Use an HTML <img> tag to output an image. The tag source attribute will be the image path/name. echo "<img src='{$sep_row['av_image']}'>";
  11. you cannot mix mysql and mysqli.
  12. You would use Windows Scheduler or a cron job (linux) to invoke the query.
  13. Assuming your table has a date column DELETE FROM tablename WHERE date_col < CURDATE() - INTERVAL 7 DAY
  14. Right now, I am as puzzled as you are.
  15. Given that the query will only return a single row, then you don't want a while() loop. Also, as you want to put the returned row into an indexed array use get_result() instead of store_result(). EG $result = $stmt->get_result(); $num_of_rows = $result->num_rows; $user = array(); if ($num_of_rows > 0) { $user = $result->fetch_row(); $user[] = $password; } $stmt->close(); return $user;
  16. I realised that, given the cumulative nature of the query, it would be dependent on knowing how many projects were open already at the start of the quarter. This would require setting the initial value of @tot to that number. It is much like a bank statement with an opening balance. Taking a pragmatic approach, I would store this balance (the final value in the query results for a quarter) in another table, in my case `projects_open` CREATE TABLE `projects_open` ( `year` year(4) NOT NULL DEFAULT '0000', `qtr` tinyint(4) NOT NULL DEFAULT '0', `bf_bal` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`year`,`qtr`) ) ; INSERT INTO `projects_open` VALUES (2014,4,2),(2015,1,3); Then my query becomes SELECT mname , @tot := @tot + opened - closed as open_at_end FROM ( SELECT MONTH(change_date) as mth , MONTHNAME(change_date) as mname , SUM(status='Open') as opened , SUM(status='Closed') as closed FROM project_status WHERE YEAR(change_date)=2015 AND QUARTER(change_date) = 1 GROUP BY mth ) totals JOIN ( SELECT @tot:= (SELECT bf_bal FROM projects_open WHERE year=2014 AND qtr=4) ) as init;
  17. To be on the safe side, in case the input is "JOHN SMITH". function getName ($first, $last, $middle='') { return ucwords(strtolower("$last, $first $middle")); } echo getName('JOHN', 'SMITH', 'K'); //--> Smith, John K Also note when using double-quotes you don't need the string concatenation.
  18. I would think that most of the time you would have written statements of requirements to work from, which would decrease the problem. Also a lot of office communication is via email or messaging. If the US is like the UK, you may find more opportunities in the public sector, and they may, in some cases, have a policy of positive discrimination (they are very fond of quotas). That gets you a foot on the career ladder.
  19. This forum is for site-related comments etc. Moving this topic to "Miscellaneous" forum.
  20. try SELECT mname , @tot := @tot + opened - closed as open_at_end FROM ( SELECT MONTH(change_date) as mth , MONTHNAME(change_date) as mname , SUM(status='Open') as opened , SUM(status='Closed') as closed FROM project_status WHERE QUARTER(change_date) = 1 GROUP BY mth ) totals JOIN (SELECT @tot:=0) as init
  21. At what point in the script are inserting the F word? Because $game is reset to Dragonball3 when you execute the findOrFail() method above.
  22. I suspect that some of your rows are duplicated because of the joins
  23. Basically, instead of $num = 43; echo $num; // --> 43 you would use $num = 43; echo "<img src='/path/$num.jpg'>"; // --> outputs image 43.jpg
  24. It will improve the appearance if you make it wide enough for a character and center the text <div style="width:10px; text-align:center;">C L A S S</div>
  25. $word = 'CLASS'; echo join('<br>', str_split($word));
×
×
  • 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.