Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. I would think the "\r\n" is the cure. Let us know.
  2. 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
  3. 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 |
  4. 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()
  5. Is it using caps in all tables? If not, why the inconsistency. (Why use caps at all?)
  6. your column names may be case-sensitive
  7. then DELETE table1, table2, table3 FROM table1 LEFT JOIN table2 USING (roomid) LEFT JOIN table3 USING (roomid) WHERE table1.time < UNIX_TIMESTAMP()
  8. 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"
  9. Given the total absence of database-related code moved from mysql to php help
  10. try DELETE table1, table2, table3 FROM table1 INNER JOIN table2 USING (roomid) INNER JOIN table3 USING (roomid) WHERE table1.time < :currenttime
  11. 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)); ?>
  12. 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|
  13. 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
  14. 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; } }
  15. 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.
  16. 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]); }
  17. Can you post/attach a dump of your data?
  18. 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.
  19. I suppose we have to keep telling you:
  20. 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
  21. 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>
  22. 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
  23. 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']}'>";
  24. you cannot mix mysql and mysqli.
×
×
  • 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.