Jump to content

Barand

Moderators
  • Posts

    24,609
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. As it said - zero-indexed, therefore 6 characters index 0 - 5 | 0 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ | A | l | i | s | o | n |
  2. You appear to be checking that the nth ball called is in the nth square on the user's card which will raise the odds of a win considerably. You should be checking if the number in each each square has been called at all, then check if the called squares match one of your patterns. For the benefit of those who don't know what you are doing, I have listed you various patterns (based on the numbers you are testing in the if() statements) in the image below. It makes your comments make more sense The cells apparently number top to bottom with 1 - 5 in the first column. From a programming perspective it would be better to put 0 - 4 in the first row, 5 - 9 in second row etc. FYI, this is the code to produce that list of patterns. Note the use of the array, which is the direction you should be taking, instead of all those if() statements. <?php $wins = [ 'airplane' => [2,3,4,8,16,18,19,20,23], 'anchor' => [1,4,6,10,11,12,14,15,16,20,21,24], 'bowtie' => [4,5,9,10,16,17,21,22], 'cents' => [7,8,9,11,14,15,17,19], 'bottle' => [8,9,10,11,12,14,15,18,19,20], 'glassempt'=> [1,7,10,14,15,17,20,21], 'glassfull'=> [1,6,7,10,11,12,14,15,16,17,20,21], 'checkmark'=> [3,4,5,9,17,21], 'chess' => [1,3,5,7,9,11,15,17,19,21,23,25], 'cornered' => [2,3,4,5,8,9,10,14,15,20], 'diamond' => [3,7,8,9,11,12,14,15,17,18,19,23], 'dollar' => [1,2,3,5,6,8,10,11,12,14,15,16,18,20,21,23,24,25], 'double' => [3,6,7,8,9,10,18,23], 'eightpack'=> [1,2,3,4,6,7,8,9], 'explosion'=> [1,5,8,12,14,18,21,25], 'corners4' => [1,5,21,25], 'gobingo' => [16,17,18,19,20,21,22,23,24,25], 'hangman' => [1,2,3,5,6,11,15,16,17,18,19,23,25], 'happyface'=> [4,6,10,15,16,20,24], 'jet' => [3,7,10,11,12,13,14,15,17,20,23], 'fullcard' => range(1,25) ]; $out = ''; foreach ($wins as $k => $nums) { $pattern = array_fill(0,25,' '); foreach ($nums as $n) { $pattern[$n-1] = '•'; } $out .= "<div class='pattern'>\n$k<br>\n<pre>\n"; for ($i=0; $i<5; $i++) { $out .= "<span class='faint'>|</span>"; for($j=0; $j<21; $j+=5) { $out .= "{$pattern[$i+$j]}<span class='faint'>|</span>"; } $out .= "\n"; } $out .= "</pre></div>\n"; } ?> <html> <head> <title>Patterns</title> <style type='text/css'> div.pattern { background-color: black; color: white; text-align: center; width: 12%; height: 120px; margin-left: 5px; margin-bottom: 5px; float: left; } .faint { color: #777; } </style> </head> <body> <?=$out?> </body> </html>
  3. And you cannot mix'n'match mysql and mysqli http://uk1.php.net/manual/en/mysqli.connect-error.php
  4. Task 1 - sort out the errors in your if() statements. I found 3 so far $n1==$nu21 $n20==$nnu20 $n21==$nu21 and $n21==$nu21 Don't create separate tables for each game (eg ...FROM numbers$gameid ) Why are you selecting 75 numbers when you only use 25? Normalize your data, db tables are not spreadsheets.
  5. I know. The sum of two cards numbered 1 - 16 would be a number between 3 and 31.
  6. 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);
  7. If we weren't, then what was to stop two comments having the same id?
  8. 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.
  9. I checked my original leopard.png image properties. I have width='1042' height='516'
  10. 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']]; ?>
  11. 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;
  12. 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.
  13. Are you prepared to remortgage your house?
  14. 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' );
  15. You know what the question is?
  16. I assume you are talking about HTML tables, that would be a ridiculous thing to do with database tables.
  17. 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(); }
  18. 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); ?>
  19. try foreach ($example as $obj) { echo $obj->fileUrl . '<br/>'; }
  20. 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 | +-------------+-----------+----------+----------+-----------+---------------------+
  21. In that case, the test data you provided, with a single prospect, is not fit for purpose
  22. What is the code where you insert the record?
  23. What have you tried so far?
  24. Not if the writer consistently omits line-breaks and indentation. I would say the key is readability.
  25. 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';
×
×
  • 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.