Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. My data mysql> SELECT * FROM database_prospects; +-------------+-----------+----------+--------+ | prospect_id | FirstName | LastName | Active | +-------------+-----------+----------+--------+ | 1 | John | Smith | 1 | | 2 | Jane | Doe | 0 | | 3 | Joe | Bloggs | 1 | | 4 | Davy | Jones | 1 | +-------------+-----------+----------+--------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM database_prospect_notes; +---------+-------------+----------+-----------+---------------------+ | note_id | prospect_id | staff_id | comment | date | +---------+-------------+----------+-----------+---------------------+ | 1 | 1 | 123 | comment 1 | 2015-07-12 00:00:00 | | 2 | 1 | 120 | comment 2 | 2015-09-14 00:00:00 | | 3 | 2 | 125 | comment 3 | 2015-06-22 00:00:00 | | 4 | 2 | 128 | comment 4 | 2015-09-01 00:00:00 | | 5 | 3 | 125 | comment 5 | 2015-08-02 00:00:00 | | 6 | 3 | 129 | comment 6 | 2015-09-05 00:00:00 | +---------+-------------+----------+-----------+---------------------+ 6 rows in set (0.00 sec) Query SELECT p.prospect_id , p.FirstName , p.LastName , notes.staff_id , notes.comment , notes.date FROM database_prospects p LEFT join ( -- -- subquery to get notes record with latest date -- SELECT n.prospect_id , n.staff_id , n.date , n.comment FROM database_prospect_notes n INNER JOIN ( -- -- subquery to find latest dates -- SELECT prospect_id , MAX(date) as date FROM database_prospect_notes GROUP BY prospect_id ) latest ON n.prospect_id = latest.prospect_id AND n.date = latest.date ) notes USING (prospect_id) WHERE p.active = 1; Results +-------------+-----------+----------+----------+-----------+---------------------+ | prospect_id | FirstName | LastName | staff_id | comment | date | +-------------+-----------+----------+----------+-----------+---------------------+ | 1 | John | Smith | 120 | comment 2 | 2015-09-14 00:00:00 | | 3 | Joe | Bloggs | 129 | comment 6 | 2015-09-05 00:00:00 | | 4 | Davy | Jones | NULL | NULL | NULL | +-------------+-----------+----------+----------+-----------+---------------------+
  2. In that case, the test data you provided, with a single prospect, is not fit for purpose
  3. What is the code where you insert the record?
  4. What have you tried so far?
  5. Not if the writer consistently omits line-breaks and indentation. I would say the key is readability.
  6. Just for fun, this was my attempt $square = [ [ 4, 9, 2], [ 3, 5, 7], [ 8, 1, 6] ]; $rowtots = []; $coltots = []; $k=count($square); // ROW and COL TOTALS for ($r=0; $r<$k; $r++) { for ($c=0; $c<$k; $c++) { if (isset($rowtots[$r])) $rowtots[$r] += $square[$r][$c]; else $rowtots[$r] = $square[$r][$c]; if (isset($coltots[$c])) $coltots[$c] += $square[$r][$c]; else $coltots[$c] = $square[$r][$c]; } } // put the totals into a sing;e array for later checking $totals = array_merge($rowtots, $coltots); // DIAGONALS TOTALS $diag1 = 0; for ($r=0, $c=0; $r<$k; $r++, $c++) { $diag1 += $square[$r][$c]; } $totals[] = $diag1; // append to array $diag2 = 0; for ($r=0, $c=$k-1; $r<$k; $r++, $c--) { $diag2 += $square[$r][$c]; } $totals[] = $diag2; // append to array // output square and result foreach ($square as $row) { echo '|'.join('|', $row).'|<br>'; } echo count(array_count_values($totals))==1 ? 'Magic square' : 'Not a magic square';
  7. Agreed, the solution is poorly written and does not address the final part of the question (order listed on the cover) My solution would be SELECT b.Title , b.PublisherCode , b.Type , GROUP_CONCAT(a.AuthorFirst,' ',a.AuthorLast ORDER BY w.Sequence SEPARATOR ', ') as WrittenBy FROM book b INNER JOIN wrote w ON b.BookCode = w.BookCode INNER JOIN author a ON w.AuthorNum = a.AuthorNum GROUP BY b.BookCode HAVING COUNT(a.AuthorNum) > 1; +----------------------+---------------+------+---------------------------------------+ | Title | PublisherCode | Type | WrittenBy | +----------------------+---------------+------+---------------------------------------+ | Treasure Chests | TA | ART | Lon Schleining, Randy O'Rourke | | Van Gogh and Gauguin | WP | ART | Bradley Collins, Jr., Bradley Collins | | Black House | RH | HOR | Stephen King, Peter Straub | +----------------------+---------------+------+---------------------------------------+
  8. The second query would be SELECT EmpID , EmpName , FormName , Scoring FROM SubmittedForm WHERE EmpID = '0001' AND submissionStatus <> 'Draft' AND fiscalYear='2015'
  9. Please use tags in future posts. I added them this time. (Or you can use the <> button in the toolbar)
  10. These are the only groups I found $a = json_decode($j,1); $groups = []; foreach ($a['response']['venues'] as $v) { $groups[] = $v['hereNow']['groups']; } echo '<pre>',print_r($groups, true),'</pre>';
  11. Are you sure that json is correct - gives my a syntax error when attempting to decode?
  12. Post the json data (results) so we can see what you are working with.
  13. Your option values do not look like numbers to me. And your WHERE condition is nothing like mine. So which bit of it did you do?
  14. Your options need the month as as the value and month name as the text <select name='month'> <option value='1'>January</option> <option value='2'>February</option> ... etc Process the month, which will be in $_GET['month'], and query the database with a query like SELECT whatever FROM mytable WHERE MONTH(dateofbirth) = ?
  15. This code is unnecessary as you are using DateTime objects. $now = time(); // this is really NOW, for comparison to your quit date $your_date = strtotime($quitdate); $datediff = $now - $your_date; You can get the vapedays from the interval object $vapedays = $interval->format('%a days');
  16. No need to pop any elements, the starting position is already Array ( [2] => 1 [3] => 3 ) since the numeric index will automatically increment after any provided numeric index. So all that is required is to add the final two elements $array['b'] = 4; $array[] = 2; // adds index 4 So, in full $array = array('2' => 1, 3); $array['b'] = 4; $array[] = 2; echo '<pre>',print_r($array, true),'</pre>'; //result Array ( [2] => 1 [3] => 3 [b] => 4 [4] => 2 )
  17. 3rd option: $fname = 'otoole.desmond.caferoyal.pdf'; $ext = strrchr($fname, '.'); echo $ext; //==> .pdf Which is what I pointed out to you in reply #2
  18. function x($a, $b) { $res = 0; while ($b) { if ($b%2) $res += $a; $a <<= 1; $b >>= 1; } return $res; } function y($j,$k) { echo chr($j+58|($k?0x20:0)); } $a = str_split(x(0xC0421DB,0x07),2) ; $b = str_split(x(0x5CDD207, 0x1E),2); array_walk($a , 'y'); echo ', '; array_walk($b , 'y');
  19. Get the mime type of the updated file and apply the extension according to that value. You are already on an outdated version of PHP, you don't want to move to a worse situation.
  20. I didn't receive that memo
  21. @QoC, See end of para 7 on http://php.net/manual/en/language.expressions.php
  22. To have $row['id'] in your results you need to select "id" in your query.
  23. you need a value for each column. You seem to have a couple of extra values at the end '".mysql_real_escape_string($data['length'])."', '', '', NOW(), 0, '') | | | | | | filesize mime ?? | | ?? added | is_done
  24. What happened to PM attachments? I can't add them any more.
  25. $real = $_FILES["file"]["name"]; // $GetName = ServerName($_FILES["file"]["name"]); $x = explode('.',$real); $GetName = time() . "." . $x[1]; If $real is "myfile.desmond.docx" then you will get desmond in $x[1]
×
×
  • 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.