Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. I know. The sum of two cards numbered 1 - 16 would be a number between 3 and 31.
  2. If you don't need to know what the two cards are then the program can reduce to a single line echo rand(3,31);
  3. If we weren't, then what was to stop two comments having the same id?
  4. I would agree to avoid dependent subqueries. As for ids, I take the view that, for the most part, they are internal linking fields and that an application should work equally well if unique ids were allocated randomly or sequentially.
  5. I checked my original leopard.png image properties. I have width='1042' height='516'
  6. It's a lot easier to use an array for the messages form <select name='language'> <option value='1'>English</option> <option value='2'>French</option> <option value='3'>German</option> <option value='4'>Klingon</option> </select> processing <?php $translations = array ( 1 => 'Welcome', 2 => 'Bienvenue', 3 => 'Herzlich Willkommen', 4 => 'yI\'el' ); echo $translations[$_GET['language']]; ?>
  7. It's actually a datetime field in the original database CREATE TABLE IF NOT EXISTS `DATABASE_Prospect_Notes` ( `note_id` int(11) NOT NULL AUTO_INCREMENT, `prospect_id` int(11) NOT NULL, `staff_id` int(11) NOT NULL, `comment` mediumtext NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`note_id`) ) [edit] PS. Using GROUP_CONCAT() can result in silent truncation when the result is > 1024 characters. As these are TEXT fields the last one may not be complete in the list. If I take out the requirement to show those with no comments (original used right join) then the query shrinks SELECT p.prospect_id , p.FirstName , p.LastName , n.staff_id , n.comment , n.date FROM database_prospects p INNER join database_prospect_notes n ON p.prospect_id = n.prospect_id INNER JOIN ( 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 WHERE p.active = 1;
  8. I got the x,y by opening the image in an image editor and hovering the mouse to see the coordinates. However, by using a grabbed image there is no guarantee that my copy is the same size as your original, hence the difference.
  9. Are you prepared to remortgage your house?
  10. I'm still not sure what you want to do (sum of which two cards?). But you could define the stack of cards like below (array keys have to be unique but not values). $cards = array ( 1 => 'Red', 2 => 'Yellow', 3 => 'Green', 4 => 'Red', 5 => 'Yellow', 6 => 'Blue', 7 => 'Yellow', 8 => 'Red', 9 => 'Yellow', 10 => 'Blue', 11 => 'Yellow', 12 => 'Green', 13 => 'Blue', 14 => 'Red', 15 => 'Blue', 16 => 'Green' );
  11. You know what the question is?
  12. I assume you are talking about HTML tables, that would be a ridiculous thing to do with database tables.
  13. You are blindly using sprintf without a clue of how to use it.(It uses placeholders in the format string to indicate the type of expression passed in the parameters) You use $grade_id in the first line then $id in subsequent lines. The values you pass to sprintf seem to plucked out of nowhere. foreach ($_POST['improvment'] as $grade_id => $status) { $remarks = $_POST['remarks'][$grade_id]; $filename = $_POST['filename'][$grade_id]; $sql = sprintf("Insert into student_evaluation(student_id,improvement,Remarks,document) Values(null, '%s', '%s', '%s')", mysqli_real_escape_string($mysqli,$improvement), mysqli_real_escape_string($mysqli,$remarks), mysqli_real_escape_string($mysqli,$filename) ); $result = mysqli_query($mysqli,$sql)or die(mysqli_error($mysqli)); } [edit] A better way is to use a prepared statement $sql = "Insert into student_evaluation(student_id,improvement,Remarks,document) Values(null, ?, ?, ?)"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('sss', $improvement, $remarks, $filename); foreach ($_POST['improvment'] as $grade_id => $status) { $remarks = $_POST['remarks'][$grade_id]; $filename = $_POST['filename'][$grade_id]; $sql->execute(); }
  14. Is this what you are trying to achieve? <?php $x1 = 224; $y1 = 94; $x2 = 663; $y2 = 487; $w = $x2-$x1; $h = $y2-$y1; $im = imagecreatetruecolor($w, $h); $src = imagecreatefrompng('leopard.png'); imagecopyresized($im,$src,0,0,$x1,$y1,$w,$h,$w,$h); imagepng($im, 'leopard_cropped.png'); imagedestroy($im); imagedestroy($src); ?>
  15. try foreach ($example as $obj) { echo $obj->fileUrl . '<br/>'; }
  16. 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 | +-------------+-----------+----------+----------+-----------+---------------------+
  17. In that case, the test data you provided, with a single prospect, is not fit for purpose
  18. What is the code where you insert the record?
  19. What have you tried so far?
  20. Not if the writer consistently omits line-breaks and indentation. I would say the key is readability.
  21. 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';
  22. 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 | +----------------------+---------------+------+---------------------------------------+
  23. The second query would be SELECT EmpID , EmpName , FormName , Scoring FROM SubmittedForm WHERE EmpID = '0001' AND submissionStatus <> 'Draft' AND fiscalYear='2015'
  24. Please use tags in future posts. I added them this time. (Or you can use the <> button in the toolbar)
  25. 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>';
×
×
  • 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.