-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
I would think the "\r\n" is the cure. Let us know.
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
So, which is correct for Dog #4? METHOD 1 | 14 | 0.0625 | 1 | 2 | | 20 | 0.0156 | 2 | 3 | | 17 | 0.0156 | 2 | 3 | | 17 | 0.0312 | 2 | 2 | | 17 | 0.0625 | 2 | 1 | Dog 4 COI : 0.1875 METHOD 2 | 14 | 0.0625 | 1 | 2 | | 20 | 0.0156 | 2 | 3 | | 17 | 0.0156 | 2 | 3 | | 17 | 0.1250 | 0 | 2 | | 17 | 0.2500 | 0 | 1 | Dog 4 COI : 0.4688- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
For dog 4, you had this for common ancestor 17 sire dam | 17 | Dog R | 2| 3,2,1| so you processed it as 0.015625 | 2 | 3 | 0.03125 | 2 | 2 | 0.0625 | 2 | 1 | Shouldn't it have been 0.015625 | 2 | 3 | 0.125 | 0 | 2 | 0.25 | 0 | 1 |- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
I see, different in each table. Need to change the syntax DELETE table1, table2, table3 FROM table1 LEFT JOIN table2 ON Rooms.id = Room_users.Roomid LEFT JOIN table3 ON Rooms.id = Room_chats.roomid WHERE table1.time < UNIX_TIMESTAMP() -
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
Is it using caps in all tables? If not, why the inconsistency. (Why use caps at all?) -
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
your column names may be case-sensitive -
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
then DELETE table1, table2, table3 FROM table1 LEFT JOIN table2 USING (roomid) LEFT JOIN table3 USING (roomid) WHERE table1.time < UNIX_TIMESTAMP() -
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
If there are possibly no matching records in table2 or table3 then use LEFT JOINS. Where are you binding the time parameter? As I've no idea what format the time is in I left that for you to set a value for "currenttime" -
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Given the total absence of database-related code moved from mysql to php help
-
PDO delete mysql records from multiple tables where the id is the same
Barand replied to cobusbo's topic in PHP Coding Help
try DELETE table1, table2, table3 FROM table1 INNER JOIN table2 USING (roomid) INNER JOIN table3 USING (roomid) WHERE table1.time < :currenttime -
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
Does this version give the results you expect? <?php $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); 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); } } function COI($id, &$dogs) { if ($id==0) return 0; $sires = $dams = []; getAncestors($dogs[$id][0], $dogs, $sires, 1); getAncestors($dogs[$id][1], $dogs, $dams, 1); $result=0; foreach ($sires as $did=>$dists) { if (isset($dams[$did])) { if (!is_null($dogs[$did][3])) { return $dogs[$did][3]; } else { $sumd = array_sum($dists) + array_sum($dams[$did]); $result += pow(0.5, 1+$sumd) * (1 + COI($did, $dogs)); $dogs[$did][3] = $result; } } } return $result; } $sql = "SELECT id, dogname, sire, dam FROM dogtable"; $dogs = array(); $res = $db->query($sql); while (list($id, $nm, $s, $d) = $res->fetch_row()) { $dogs[$id] = [$s,$d,$nm,null]; } $dogid = 9; printf("Dog %d COI : %0.3f", $dogid, COI($dogid, $dogs)); ?>- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
The problem is the function was only storing one occurrence per ancestor. Try this $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); function getAncestors($id, &$dogs, &$ancests, $dist) { if ($id==0) return; $ancests[$id][] = $dist; // <-- changed to store more than 1 distance if (isset($dogs[$id]) ) { getAncestors($dogs[$id][0], $dogs, $ancests, $dist+1); getAncestors($dogs[$id][1], $dogs, $ancests, $dist+1); } } $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]; } $dogid = 1; getAncestors($dogs[$dogid][0], $dogs, $sires, 1); getAncestors($dogs[$dogid][1], $dogs, $dams, 1); ksort($sires); ksort($dams); echo '<pre>sires ',print_r($sires, true),'</pre>'; echo '<pre>dams ',print_r($dams, true),'</pre>'; $common = array_intersect_key($sires,$dams); echo "<pre>"; echo "| ID | NAME | SIRE | DAM |\n"; echo "| | | DIST | DIST |\n"; echo "|-----|--------------------|------|------|\n"; foreach ($common as $id => $dist) { printf("|%4d | %-18s |%6s|%6s|\n", $id, $dogs[$id][2], join(',', $sires[$id]), // changed to show the join(',', $dams[$id]) ); // multiple distances } Now gives results like | ID | NAME | SIRE | DAM | | | | DIST | DIST | |-----|--------------------|------|------| | 8 | dog I | 3| 2| | 10 | dog K | 4,3| 3| | 16 | dog Q | 4| 3| | 17 | dog R | 4| 3| | 20 | dog U | 5,4| 4| | 21 | dog V | 5,4| 4|- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Ticket reservation system, array assistence needed
Barand replied to jiros1's topic in PHP Coding Help
You need to take seat location into account. If you have, say, 10 seats in 2 rows of 5 seats 1-3 are booked 3 people require seats 1* 2* 3* 4 5 6 7 8 9 10 then allocating seats 4,5,10 would be a better solution than 4,5,6 similar post that may help http://forums.phpfreaks.com/topic/284542-allocated-seating-layout-help/?do=findComment&comment=1461309 -
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
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; } }- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
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.
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
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]); }- 40 replies
-
- 1
-
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
Can you post/attach a dump of your data?- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Return records from table and display each weeks data in a separate row
Barand replied to djs1971's topic in MySQL Help
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. -
I suppose we have to keep telling you:
-
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
-
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>
-
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
-
you cannot mix mysql and mysqli.