-
Posts
24,612 -
Joined
-
Last visited
-
Days Won
834
Everything posted by Barand
-
Column 'description' cannot be part of FULLTEXT index
Barand replied to Destramic's topic in MySQL Help
You need MySQL 5.6+ for fulltext on InnoDB -
I need some help. Trying to show label before showing pictures in a row.
Barand replied to vet911's topic in PHP Coding Help
Check for changes in the title value. When a new value is encountered, output the new title. pseudocode: prev = ''; while (fetch next row) { if (title != prev) { output title prev = title // reset previous value } output image } -
Help understanding why this Mysql Query is badly designed.
Barand replied to blmg2009's topic in MySQL Help
I am surprised it runs as quickly as it does given all those dependent subqueries. For every record read you perform 15+ subqueries. Get rid of those subqueries and use JOINS. -
Seems a pointless question but, yes, so long as you don't want to change the company name.
-
As long as your existing id is "1" then the version you had in #3 should work. (It worked for me)
-
This is an example of a function I use for UK holidays, but should be easily adaptable. In UK, if the holiday falls at weekend, the day-off is the following Monday. function publicHols($yr) { // CALC PUBLIC HOLS FOR $yr $hols = array(); $newyr = "$yr-01-01"; switch (date('w', strtotime($newyr))) { case 6: $newyr = "{$yr}-01-03"; break; case 0: $newyr = "{$yr}-01-02"; break; } $hols['New Year'] = array($newyr,$newyr); $easter = easter_date($yr); $hols['Easter'] = array(date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter))); $mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d'); $hols['May Day'] = array($mayday,$mayday); $sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d'); $hols['Spring Bank'] = array($sbank,$sbank); $abank = (new DateTime("last monday of august $yr"))->format('Y-m-d'); $hols['August Bank'] = array($abank,$abank); $x1 = "$yr-12-25"; $x2 = "$yr-12-26"; switch (date('w', strtotime($x1))) { case 5: $x2 = "$yr-12-28"; break; case 6: $x1 = "$yr-12-27"; $x2 = "$yr-12-28"; break; case 0: $x1 = "$yr-12-26"; $x2 = "$yr-12-27"; break; } $hols['Christmas'] = array($x1,$x2); return $hols; } function showReminders($yr) { $hols = publicHols($yr); $today = new DateTime(); $today->setTime(0,0); foreach ($hols as $h=>$dates) { $dh = new DateTime($dates[0]); $days = $dh->diff($today)->format('%a days'); if ($dh==$today) { echo "It's $h!<br>"; } elseif ($dh > $today && $days <= 7) { echo $today->format('jS F Y')." reminder, $h in $days<br>"; } } } $year = date('Y'); showReminders($year); showReminders($year+1);
-
Split numbers from '-' delimited list and enter them into an array
Barand replied to bluefrog's topic in PHP Coding Help
Yes, explode() will put the numbers into an array. sort() will put the array in ascending values. Use a foreach() loop to echo the elements in the array. -
If there should only ever be a single record in that table why have an auto_incrementing id why even attempt to insert a new record? Just update the existing one
-
So what are the ids of the records now in your table?
-
Did you already have a record with an id of "1"? The id would be the id of the record to be updated, not 1 every time.
-
You aren't inserting the id into the new record so you are not attempting to create a duplicate
-
-
Your date format is invalid for storing in a database table, it needs converting to YYYY-mm-DD. Numeric values cannot contain "£".
-
Whenever you have column names like room_type_1, room_type_2, ..., room_type_N, the database design is wrong. Database tables are not spreadsheets. You should normalize the data so each of those room_type values is in a row of its own. (See attached model.). Don't use SELECT *. Specify just the column you need. Use explicit join syntax instead of putting the join conditions in the WHERE clause. Using the attached model, the query you want would be SELECT h.hotel_num , h.name , SUM(hi.qty) as rooms FROM hotel h INNER JOIN event_hotels eh ON h.hotel_num = eh.hotel_num INNER JOIN hotels_inventory hi ON h.hotel_num = hi.hotel_num WHERE eh.event_num = 78 AND hi.inv_date BETWEEN '2015-12-01' and '2015-12-31' GROUP BY h.hotel_num ORDER BY rooms DESC;
-
You can calculate the distance in the query and then ORDER BY distance
-
Creating a database or... (CAR/TYRE guys take a look)
Barand replied to IamSuchANoob's topic in Application Design
to process a single line like that you can $str = 'Mark;;Mudel;;;Mootor;;;;;;;Laius Kõrgus ZR;;"R """;;LI;SI;XL e4txc4;;;;;;;;;;;;;;;;;;;;;;;;'; $data = array_filter(str_getcsv($str,';')); // ignore empty values echo '<pre>',print_r($data, true),'</pre>'; // view the data array which gives Array ( [0] => Mark [2] => Mudel [5] => Mootor [12] => Laius Kõrgus ZR [14] => R " [16] => LI [17] => SI [18] => XL e4txc4 ) To process the whole file you use fgetcsv, which is similar. -
We won't do your homework for you. Use meaningful topic titles in future
-
Need help with script that copies JPG to different quality settings
Barand replied to mreish's topic in PHP Coding Help
That is what you said you want to do. If you want to reduce the quality each time then don't hard-code the "50", put it in a variable and reduce the value in each loop -
Using date comparison in an if statement
Barand replied to ohboyatoytruck's topic in PHP Coding Help
You cannot compare dates correctly using that date format. Always use yyyy-mm-dd for date storage and comparisons. Format as required on final output. -
What should be a simple issue is making me nuts... Help please.
Barand replied to Johninbc's topic in PHP Coding Help
You need to pass 4 parameters when you connect, not just 1. Try $conn = "mysqli_connect(db_host, db_user, db_pass, db_name)"; and don't post db credentials. -
If we knew your input data, what you are getting and what you expect to get then maybe we'd have some ideas.
-
Only checked checkbox values are posted so you need to do something like this $captcha_reset_pass = isset($_POST['captcha_reset_pass'] ? 'yes' : 'no';
-
there are some conversion programs around http://lmgtfy.com/?q=php+html+to+pdf+conversion
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
This my best attempt yet. Instead of counting I store the traversed path then eliminate duplicates. <?php // // ARRAY OF DOGS // id => [sire, dam, name] // $dogs = array ( 1 => array ( 0 => '2', 1 => '3', 2 => 'Nimh\'s Delorean', ), 2 => array ( 0 => '4', 1 => '9', 2 => 'Dog B', ), 3 => array ( 0 => '7', 1 => '8', 2 => 'Dog C', ), 4 => array ( 0 => '7', 1 => '9', 2 => 'Dog E', ), 5 => array ( 0 => '10', 1 => '11', 2 => 'Dog F', ), 7 => array ( 0 => '14', 1 => '15', 2 => 'Dog H', ), 8 => array ( 0 => '16', 1 => '17', 2 => 'Dog I', ), 9 => array ( 0 => '16', 1 => '17', 2 => 'Dog J', ), 10 => array ( 0 => '18', 1 => '19', 2 => 'Dog K', ), 11 => array ( 0 => '20', 1 => '21', 2 => 'Dog L', ), 14 => array ( 0 => '20', 1 => '17', 2 => 'Dog O', ), 15 => array ( 0 => '0', 1 => '0', 2 => 'Dog P', ), 16 => array ( 0 => '14', 1 => '17', 2 => 'Dog Q', ), 17 => array ( 0 => '0', 1 => '0', 2 => 'Dog R', ), 18 => array ( 0 => '0', 1 => '0', 2 => 'Dog S', ), 19 => array ( 0 => '0', 1 => '0', 2 => 'Dog T', ), 20 => array ( 0 => '0', 1 => '0', 2 => 'Dog U', ), 21 => array ( 0 => '0', 1 => '0', 2 => 'Dog V', ), 22 => array ( 0 => '0', 1 => '0', 2 => 'Dog W', ), 23 => array ( 0 => '0', 1 => '0', 2 => 'Dog X', ), 24 => array ( 0 => '25', 1 => '26', 2 => 'Cedric', ), 25 => array ( 0 => '27', 1 => '0', 2 => 'Phantom', ), 26 => array ( 0 => '27', 1 => '0', 2 => 'Walton Mare', ), 27 => array ( 0 => '0', 1 => '0', 2 => 'Walton', ), 28 => array ( 0 => '0', 1 => '0', 2 => 'A', ), 29 => array ( 0 => '0', 1 => '0', 2 => 'B', ), 30 => array ( 0 => '29', 1 => '28', 2 => 'C', ), 31 => array ( 0 => '29', 1 => '28', 2 => 'D', ), 32 => array ( 0 => '0', 1 => '30', 2 => 'E', ), 33 => array ( 0 => '0', 1 => '31', 2 => 'F', ), 34 => array ( 0 => '33', 1 => '32', 2 => 'I', ), 35 => array ( 0 => '0', 1 => '0', 2 => 'J', ), 36 => array ( 0 => '0', 1 => '0', 2 => 'K', ), 37 => array ( 0 => '0', 1 => '0', 2 => 'L', ), 38 => array ( 0 => '0', 1 => '0', 2 => 'M', ), 39 => array ( 0 => '0', 1 => '0', 2 => 'N', ), 40 => array ( 0 => '0', 1 => '0', 2 => 'Dog1', ), 41 => array ( 0 => '0', 1 => '0', 2 => 'Dog2', ), 42 => array ( 0 => '40', 1 => '41', 2 => 'Dog3', ), 43 => array ( 0 => '42', 1 => '41', 2 => 'Dog4', ), 44 => array ( 0 => '0', 1 => '0', 2 => 'O', ), 45 => array ( 0 => '0', 1 => '0', 2 => 'P', ), 46 => array ( 0 => '44', 1 => '45', 2 => 'Q', ), 47 => array ( 0 => '44', 1 => '45', 2 => 'R', ), 48 => array ( 0 => '46', 1 => '47', 2 => 'S', ), 49 => array ( 0 => '46', 1 => '47', 2 => 'T', ), 50 => array ( 0 => '48', 1 => '49', 2 => 'U', ), 51 => array ( 0 => '0', 1 => '0', 2 => 'A', ), 52 => array ( 0 => '0', 1 => '0', 2 => 'B', ), 53 => array ( 0 => '51', 1 => '52', 2 => 'C', ), 54 => array ( 0 => '51', 1 => '52', 2 => 'D', ), 55 => array ( 0 => '51', 1 => '52', 2 => 'E', ), 56 => array ( 0 => '51', 1 => '52', 2 => 'G', ), 57 => array ( 0 => '53', 1 => '54', 2 => 'H', ), 58 => array ( 0 => '55', 1 => '56', 2 => 'I', ), 59 => array ( 0 => '57', 1 => '58', 2 => 'J', ), 60 => array ( 0 => '59', 1 => '50', 2 => 'Z', ) ); // // CALCULATE INBREEDING COEFFICIENTS // $doglist = [4,9,34,50,59,60]; echo "<pre>\n"; foreach ($doglist as $dogid) { printf("%-20s (#%03d) COI : %0.4f<br>", $dogs[$dogid][2], $dogid, COI($dogid, $dogs)); } echo "</pre>\n"; // // FUNCTIONS // function getAncestors($id, &$dogs, &$ancests, $path) { if ($id==0) return; $ancests[$id][] = $path; if (isset($dogs[$id]) ) { getAncestors($dogs[$id][0], $dogs, $ancests, $path.$dogs[$id][0].','); getAncestors($dogs[$id][1], $dogs, $ancests, $path.$dogs[$id][1].','); } } function COI($id, &$dogs) { if ($id==0) return 0; $sires = $dams = []; getAncestors($dogs[$id][0], $dogs, $sires, ''); getAncestors($dogs[$id][1], $dogs, $dams, ''); $result=0; foreach ($sires as $did=>$dists) { if (isset($dams[$did])) { $distd = $dams[$did]; foreach ($dists as $paths) { foreach ($distd as $pathd) { $ds = count(explode(',', $paths)); $dd = count(explode(',', $pathd)); if ($paths==$pathd && $ds>2) continue; $sumd = $ds + $dd-1; $intermed = pow(0.5, $sumd) * (1 + COI($did, $dogs)); $result += $intermed; // printf("| %5s | %8.4f | %12s | %12s |\n", $dogs[$did][2], $intermed, $paths, $pathd); } } } } return $result; } Results Dog E (#004) COI : 0.1875 Dog J (#009) COI : 0.3750 I (#034) COI : 0.0625 U (#050) COI : 0.3750 J (#059) COI : 0.2500 Z (#060) COI : 0.0000- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Update field but do nothing when field value equals
Barand replied to cobusbo's topic in PHP Coding Help
I agree with ginerjm, that's a terrible table design. Make it a datetime field with a value of '9999-12-31 23:59:59' for those that are permanent. Then your query works as it is now (except you would use NOW() instead of UNIX_TIMESTAMP() ) As it is now, are you saying you want to update the "kick" fields where kick < UNIX_TIMESTAMP() AND kick <> 'Permanently' ?