Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. ... and obsolete PHP functions. split is deprecated too.
  2. You should forget the global keyword exists and avoid using it. Pass the value to the function. You can either pass the array function growl_based_notification($context) { if (!empty($context['user']['mentions']) > 0) // Say they have unread alerts. ... } growl_based_notification($context) // call function or just pass the part of the array that you need function growl_based_notification($mentions) { if (!empty($mentions) > 0) // Say they have unread alerts. ... } growl_based_notification($context['user']['mentions']) // call function
  3. How are you running the query and processing the result?
  4. Your function expects the $context array When you call it you pass just the single element of the array Call the function with growl_based_notification($context);
  5. Then remove that bit of the code.
  6. "n" is at position 5. (see reply #2 ) $name = 'Alison'; echo $name[5]; //--> n "A" is at position 0 echo $name[0]; //--> A When using substr you give the start index and the number of characters echo substr($name,2,3); //-> iso It also gives you the the option of counting from the end of the string, using negative offset values (as jaques1 stated) echo substr($name,-3,3); //--> son echo substr($name,-1,1); //--> n substr
  7. As it said - zero-indexed, therefore 6 characters index 0 - 5 | 0 | 1 | 2 | 3 | 4 | 5 | +---+---+---+---+---+---+ | A | l | i | s | o | n |
  8. 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>
  9. And you cannot mix'n'match mysql and mysqli http://uk1.php.net/manual/en/mysqli.connect-error.php
  10. 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.
  11. I know. The sum of two cards numbered 1 - 16 would be a number between 3 and 31.
  12. 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);
  13. If we weren't, then what was to stop two comments having the same id?
  14. 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.
  15. I checked my original leopard.png image properties. I have width='1042' height='516'
  16. 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']]; ?>
  17. 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;
  18. 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.
  19. Are you prepared to remortgage your house?
  20. 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' );
  21. You know what the question is?
  22. I assume you are talking about HTML tables, that would be a ridiculous thing to do with database tables.
  23. 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(); }
  24. 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); ?>
  25. try foreach ($example as $obj) { echo $obj->fileUrl . '<br/>'; }
×
×
  • 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.