Jump to content

kicken

Gurus
  • Posts

    4,079
  • Joined

  • Last visited

  • Days Won

    128

Everything posted by kicken

  1. There is no align: property for CSS. For aligning inline elements like an image you want text-align:
  2. The Null Coalescing operator provides a fallback value if the previous value is null (or doesn't exist). $displayName = $_POST['displayName'] ?? 'Anonymous'; Using ?? there is a shorter way of writing if (isset($_POST['displayName'])){ $displayName=$_POST['displayName']; } else { $displayName='Anonymous'; } Using ?? to provide a fallback value prevents PHP from complaining about undefined variables/indexes. If you don't have an appropriate default value to provide, you can just use null.
  3. I don't think there is a difference between the two lines of code. For the configuration settings, the information is in the manual. Look at the Changable column to find out where a directive can be changed.
  4. It's not PHP that is timing out, it's Apache. It's waiting for the PHP process to provide a response but it eventually gives up. You can set it's timeout duration using Timeout or ProxyTimeout.
  5. Have you made sure your destination supports large files? That it's not formatted with FAT32 for example. I copy > 4GB database backup files regularly with PHP.
  6. That's not what happens. A datetime string can be composed of various bits of information and one of those bits of information is a timezone. For example you could specify "2021-12-06 9:32:00 EST". In the formats documentation it says: So the example there's a "Date Format" part a "Time Format" part. In the Time Formats formats documentation, there's an entry saying it will recognize a timezone name. You don't need to specify every bit of information when providing a date/time string. Missing bits will be determined based on the current time usually. As such, specifying only a timezone abbreviation/name is a valid entry and it will parse as the current time, but with the timezone set as X. And I would rather ensure I have known correct data rather than something totally unexpected like what prompted this thread. Just checking for a - or a / isn't going to help, as it'd still allow entries like "America/New_York" or "UTC-7:00" Forcing a fixed format or two in my experience works nearly all the time. You can log failures so that if a particular format occurs often you can add it to the list. I usually just inform people what the expected format is though. You make the separator flexible by using ? or * instead of a defined separator if that's one of your concerns. Eg: Y*m*d would accept both 2021-12-06 and 2021/12/06.
  7. I'd use DateTime::createFromFormat. Ideally you'd want the dates to be in a specific format. If you can't do that, I'd just try a few of the most common formats in a particular order (ie, Y-m-d, m/d/Y, ...)
  8. You need to read up on database normalization. What you need to do is have a table where each category is a row, not a column and then join that to your other tables.
  9. Your project contains libraries that require PHP 7.4 or newer but your server is running PHP 7.3. The system you used to develop the project must have a newer version of PHP, so when you ran composer there and generated the composer.lock file it did so assuming PHP 7.4 or newer was being used. You should update your server to a newer PHP version. For the future, you should also make sure your development system matches your production system as closely as possible.
  10. use a join rather than sub queries in the select clause. select u.id, u.user_login, u.user_email, u.user_registered, sub_level.meta_value as sub_level, sub_region.meta_value as sub_region from wp_users u inner join wp_usermeta sub_level on u.id = sub_level.user_id and sub_level.meta_key = 'wp_capabilities' and sub_level.meta_value like '%s2member_%' inner join wp_usermeta sub_region on u.id = sub_region.user_id and sub_region.meta_value like '%county%' Does the region not have an appropriate meta_key value to filter on?
  11. You can simply use the null coalescing operator when reading the values from your array to remove the warning. $num = $leaddata[$status][$title] ?? null; $contacts = $leaddatastatus[$status][$title][$sub_status] ?? null;
  12. You can use static methods in an interface. For example, Symfony's EventSubscriberInterface.
  13. Do you maybe mean $documentArray and not $notesArray there?
  14. You only loop through your posts until $count = $limit, then you stop. As such, $count will never exceed $limit so your if ($count > $limit) check later on will always be false, resulting in your code responding with the noMostPosts = true marker. What you need to do is stop outputting posts when $count > $limit in your loop, but continue to increment count so your code later knows if there are more pages or not.
  15. Your adding the ID to the content of the file right there. If you don't want the ID number in the file, then don't add it. $file['content']=$content;
  16. You call your method like so: Suggesting that the first parameter is going to be the user id passed in from the URL. Then you have your method which looks like: Here, the first parameter is an array that you're trying to extract the page key from. You also seem to ignore the userLoggedIn parameter here and just get the user id from within the class somewhere. You could just pass in $_REQUEST for the first parameter, but it might be nicer to change the first parameter to be $page and pass in $_REQUEST['page']. public function getUserPosts($page, $limit){ $userLoggedIn = $this->user->username; //...everything else } //Then call it $posts->getUserPosts($_REQUEST['page'], 10); If you're still having isssues, then you need to debug the ajax requests to see what's happening. You do that with your browser's developer tools (F12). Look at the networking tab which will show all the requests made by the browser and find the ajax request in the list. Check to see if the request returns a successful response (200) and check the details of the request by selecting it. In the details you can find the parameters that were sent and the response that was returned. Look at the response that was returned and make sure it is what you're expecting it to be.
  17. If you want keys, you need to define them when you create the array. while($stmt -> fetch()){ $awards[$ay][$id] = ['an' => $an, 'aw' => $aw]; } Then you can use $winner['an'] / $winner['aw'] instead.
  18. Your top level array is a list of award years. Inside each year is a list of winners. If you want to loop through it all, just use two nested foreach loops. $awardYearsList = getExistingAwards(); foreach ($awardYearsList as $awardYear => $winnerList){ echo '<p>Winners in award year '.$awardYear.':</p>'; foreach ($winnerList as $winner){ echo '<p>'.$winner[0].' - '.$winner[1].'</p>'; } }
  19. Yes. You're loading your existing comments in the constructor of the Comments class, so all your data gets loaded here: $comment = new Comment(Input::get("post_id")); The data you load at that point is what you'll end up displaying later on when you call display() and count(). Whether or not $message is true isn't really relevant to how this functions. That's wrong from a syntax perspective. If that's what you have, you should be getting a syntax error I would think. You don't use <?php ?> tags to embed variables into strings. You use concatenation and/or interpolation. Redirect::to("single_post.php?post_id=$post_id&related=$related"); With the syntax fixed, replace your $message = true; line with the redirect. You'll need to use an alternate means of determining whether or not to show your message, such as by adding a message=true parameter to the URL or storing something in the session. This is possibly related to the bad syntax of the redirect. Notice in the stack trace it shows the php tags as part of the parameters: Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /opt/lampp/htdocs/qcic/assets/class/DB.php:35 Stack trace: #0 /opt/lampp/htdocs/qcic/assets/class/DB.php(35): PDOStatement->execute() #1 /opt/lampp/htdocs/qcic/assets/class/DB.php(121): DB->query('UPDATE posts SE...', Array) #2 /opt/lampp/htdocs/qcic/assets/class/Post.php(227): DB->update('posts', '<?php echo 86; ...', Array) ------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^ #3 /opt/lampp/htdocs/qcic/newsnet/single_post.php(16): Post->viewCount('<?php echo 86; ...') ---------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^ #4 {main} thrown in /opt/lampp/htdocs/qcic/assets/class/DB.php on line 35
  20. Essentially it's the same problem you had with your count. The original problem with the count was that you were trying to echo the count before you loaded the data. The new problem is because you're loading the data before you insert the new comment. There are a few ways you could solve the issue. You could simply re-load the data after adding a new comment. You could re-arrange you code to submit the new comment first, then load the data after. You could leave the code as-is, but redirect the user after adding a comment so the page gets reloaded automatically. Typically when submitting data you'd do a redirect as in option #3. That is known as a Post/Redirect/Get process and prevents people re-submitting duplicate data by trying to reload the page after making a submission.
  21. If it's just two, it's probably not worth effort to create some generic solution. Just add each call individually. document.getElementById('whatever1').addEventListener('click', function(){ clear_input('button1', 'hello1', 'world1'); }); document.getElementById('whatever2').addEventListener('click', function(){ clear_input('button2', 'hello2', 'world2'); }); If you need a more generic solution you'll need to explain more about the situation, like why the arguments are 'button1', 'hello1', 'world1' to start with.
  22. Move the first part of your display method that loads the data into it's own method and call it from the constructor.
  23. Alternatively, as I mentioned in another thread of yours, stop trying to manipulate the styles directly like that and just apply/remove a class. js: function toggleResponseArea(){ document.getElementById('comment-area').classList.toggle('removed'); } css: .removed { display: none; }
  24. I change the fwrite you had to be followed by "\n" instead of "\r", did you try changing that back? If that doesn't help, you'll have to do some debugging locally and try to figure it out. Works ok for me with my ardiuno loaded with a quick test program to read the analog pins. kicken@ubuntu-dev:/Workspace/serial$ php serial_linux.php read_a0 string(32) "readLength=7 cmd=read_a0 793 "
  25. This code worked for me using a VM with ubuntu on it. When reading the results after sending the command it will hang for at least as long as the timeout period before returning results since there's no way to determine when the serial device is done sending data otherwise. <?php $cmd = implode(' ', array_slice($argv, 1)); $device = serialSetup('/dev/ttyS0', 115200, 8); var_dump(serial($device, $cmd ?: 'uname -a')); fclose($device); function serialSetup($device, $baud, $data){ $cmd = sprintf('stty -F %s %d cs%d -echo raw', $device, $baud, $data); exec($cmd, $output, $ret); if ($ret !== 0){ var_dump($output); throw new \RuntimeException('Unable to configure serial device'); } $f = fopen($device, "w+"); if (!$f){ throw new \RuntimeException('Unable to open serial device.'); } stream_set_blocking($f, false); return $f; } function serial($device, $cmd){ fwrite($device, $cmd . "\n"); $result = ''; do { try { $result .= serialRead($device, 5); $timeout = false; } catch (RuntimeException $ex){ $timeout = true; } } while (!$timeout); return $result; } function serialRead($device, $timeout = 30){ $r = [$device]; $w = $e = []; $n = stream_select($r, $w, $e, $timeout, 0); if ($n === 1){ $line = fgets($device) ?: ''; if ($line !== ''){ return $line; } } throw new \RuntimeException('Timeout reading from serial device'); } For the curious, this also sort of works on windows. The timeout cannot be controlled on windows, so you're stuck with the default (around 120 seconds). The stty call needs to be replaced with the following call to mode and of course use the appropriate device name (ie, COM1). The important bit seems to be the to=on parameter in the call to mode, without it windows seems to never timeout on a read and the script would hang indefinitely. $cmd = sprintf('mode %s BAUD=%d PARITY=n DATA=%d to=on', $device, $baud, $data);
×
×
  • 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.