Jump to content

requinix

Administrators
  • Posts

    14,237
  • Joined

  • Last visited

  • Days Won

    369

Community Answers

  1. requinix's post in shorthand syntax help was marked as the answer   
    If I may translate that,

    If you mean the ternary operator ? : then the answer is,
    While possible, in this case you shouldn't. That's more appropriate if you have "if ($condition) $var = $value; else $var = $other_value;". Your if has two statements in that else so it's really just better to leave it as is. And this is coming from someone who generally does use shorthand.
  2. requinix's post in listing multiple arrays in order was marked as the answer   
    FYI, next time you post code, make sure you remove sensitive information like the appid you had in that URL.
     
    So that code makes more sense than the one earlier, and doesn't have as much that needs to change.
     
    You already have a loop that goes over all the locations, so do the work of determining the highest and lowest in there.
    Do you only care about the temperatures? You like you don't care where the temperatures are from - just what they are?

    <?php session_start(); include_once("cxn.inc"); $today = date("Y-m-d H:i:s"); $sql = "SELECT airports.Name,airports.Country FROM airports INNER JOIN rosters ON airports.IATA = rosters.Arr WHERE rosters.Code = '$code' AND rosters.SectorDate >= '$today'"; $result = mysqli_query($cxn,$sql) or die ($cxn->error); $coldest = $hottest = null; while($row=mysqli_fetch_assoc($result)) { $link = 'http://api.openweathermap.org/data/2.5/weather?q='.$row['Name'].','.$row['Country'].'&units=metric&mode=xml&appid=*'; /* WEATHER API */ $xml=simplexml_load_file("$link") or die ("Cannot create object."); $temp = (int)$xml->temperature['value']; // converting to int is important or you'll have a bunch of SimpleXMLElement objects if (is_null($coldest) || $temp < $coldest) { $coldest = $temp; } if (is_null($hottest) || $temp > $hottest) { $hottest = $temp; } } /// OUTPUT GOAL /// echo $coldest; echo '<br />'; echo $hottest; ?>
  3. requinix's post in form submission was marked as the answer   
    Not both at once. One at a time. Because if you read the documentation for mysqli_query() you would know what the arguments to it are and that it only does one query.
  4. requinix's post in What is this about? was marked as the answer   
    I removed your warning and reset you back to 0 warning points. Sorry about the misunderstanding.
  5. requinix's post in Getting only last date of transaction with join was marked as the answer   
    If you're not pulling in data from any other tables, and all you need from the transaction table is the date, then use MAX with a GROUP BY on the user.

    SELECT c.firstname, c.surname, c.regDate, MAX(t.lastTrans) AS lastTrans FROM confirmed c LEFT JOIN transaction t ON c.user_id = t.user_id WHERE c.status = 'confirmed' GROUP BY c.user_id ORDER BY MAX(t.lastTrans)
  6. requinix's post in php array variable question... was marked as the answer   
    And there it is. 
    See, the "url" param, and thus the $url variable, and thus the $urls array, contains a string of all the URLs. That's no good. Your code needs an array of individual URLs, not all of them bunched together.
     
    1. You copied and pasted that

    'http://www.dallascowboys.com/rss/video', 'http://www.dallascowboys.com/rss/gallery', 'http://www.dallascowboys.com/rss/audio', 'http://espn.go.com/blog/feed?blog=nfceast', 'https://sports.yahoo.com/nfl/teams/dal/rss.xml',into the textarea. You, as a user, need to fix that so it becomes
    http://www.dallascowboys.com/rss/video http://www.dallascowboys.com/rss/gallery http://www.dallascowboys.com/rss/audio http://espn.go.com/blog/feed?blog=nfceast https://sports.yahoo.com/nfl/teams/dal/rss.xmlOne URL for each line. No extra apostrophes or commas or anything. Make sure your form has instructions to do that. 
    2. Now you know each line is a URL. Supposedly. IMO the best way to get the individual URLs out of it is to try to locate a valid URL on each line, which gives you some freedom about leaving blank lines and such:

    $url = $params->get('url'); // beginning of line, maybe whitespace, a "http://" or "https://" url, maybe more whitespace, then the end of the line if (preg_match_all('/^\s*(https?://\S+)\s*$/im', $url, $matches, PREG_PATTERN_ORDER)) { $urls = $matches[1]; } else { // did not find any urls $urls = array(); }3. Now that you have $urls set you don't need
    /********* Feeds *********/ $urls = array($url); /********* Feeds *********/
  7. requinix's post in PDO connection - getaddrinfo failed: was marked as the answer   
    "mysql:host=HOST;dbname=DB_NAME"PDO doesn't know that "HOST" and "DB_NAME" are PHP constants. You have to put the values in yourself.
    "mysql:host=" . HOST . ";dbname=" . DB_NAME
  8. requinix's post in array not showing real 'reset' value inside while statement was marked as the answer   
    <?php $sqlfriend = "SELECT * FROM Users INNER JOIN friends ON friends.FriendCode = Users.Code WHERE friends.Code = '{$_SESSION['Code']}' ORDER BY Users.Code DESC"; $resultfriend = mysqli_query($cxn,$sqlfriend) or die ("Cant get friends."); while($rowfriend=mysqli_fetch_assoc($resultfriend)) { // CHECKS IF WORKING, STBY or OFF $sql = "SELECT Duty,BeginTime,EndTime FROM rosters WHERE Code = '{$rowfriend['FriendCode']}' AND SectorDate = '$today' ORDER BY BeginTime ASC"; $result2 = mysqli_query($cxn,$sql) or die ("Cant find out friends duties for today."); $duty = mysqli_fetch_assoc($result2); if(strpos($duty['Duty'],'SBY') !== false) { // friend STBY $border = 'warning'; $friendsdutytoday = 'Today: <br /> <b>Standby until '.$duty['EndTime'].'</b>'; } elseif (strpos($duty['Duty'],'OFF') !== false || strpos($duty['Duty'],'A/L') !== false || strpos($duty['Duty'],'ADHOC') !== false) { // friend $border = 'success'; $friendsdutytoday = 'Today: <br /> <b>'.$duty['Duty'].'</b>'; } elseif(is_numeric($duty['Duty'])){ // friend WORKING $starttimes = array(); $finishtimes = array(); while($duty=mysqli_fetch_assoc($result2)) { $starttimes[] = $duty['BeginTime']; $finishtimes[] = $duty['EndTime']; } $border = 'info'; $friendsdutytoday = 'Working today <br />'; foreach($starttimes as $value) { echo $value; } echo '<b>'.reset($starttimes).'Z - '.end($finishtimes).'Z</b>'; /////// ERROR ECHOED HERE ///////// } else { $border = 'info'; $friendsdutytoday = 'Today <br /> <b>No Roster</b>'; }Right. Because the first row is the $duty you fetched on line 15. When you start the while loop (31) you throw away $duty and start fetching more rows. 
    Instead of using an empty array for $starttimes and $finishtimes, use an array with the values you already have in $duty.
  9. requinix's post in PHP looping through array was marked as the answer   
    Seems weird that you have this mixture of numbers and strings, but whatever.
     
    So you only want to add to $SLevels if the data is a number? I figure

    if($tmp[0] != '-')would be a good place to do that. To test for a number, try is_numeric.
  10. requinix's post in help with register globals was marked as the answer   
    If you have stuff written from back when register_globals was acceptable then it's been a very long time and your code probably needs a once-over. Not just for this problem but potentially others.
     
    Otherwise the best thing you can do is fix the code. Really. It might take a while but all you need is stuff like

    $variable = (isset($_GET["variable"]) ? $_GET["variable"] : "reasonable default value");or
    if (isset($_GET["variable"])) { $variable = $_GET["variable"]; } else { // show an error }
  11. requinix's post in What is wrong with this form? was marked as the answer   
    Ah, hosting support...
     
    Form inputs only work if you give them names. The IDs are just for the client side - mostly Javascript.

    <form method="post" action="#"> <input type="text" id="date1" name="post1" size="8"> <br /> <input type="text" id="date2" name="post2" size="8"> <br /> <input type="submit" name="submit"> </form>
  12. requinix's post in users accessing my localhost was marked as the answer   
    1. The server has to be listening on your LAN IP address. 127.0.0.1 will only work for connections from the same computer.
    2. Make sure your firewall allows inbound connections to that port.
    3. Set up a port forwarding on your router from whatever port to your LAN IP address (and port).
  13. requinix's post in How to convert simple jQuery to plain JS was marked as the answer   
    onfocus="this.readonly=false;" readonly is a boolean attribute on most s. 
    Unless you want to actually remove the existing readonly attribute. The primary difference is what would happen if the form is reset.

    this.removeAttribute('readonly')
  14. requinix's post in Find n in algorithm was marked as the answer   
    Alright.
     
    Use a DateTime for the chosen date and diff it to starting date. That will give you a DateInterval which can tell you how many days are between the two dates. Since you don't care about the number of cycles between the two dates (k from before) all you have to do is use modulus to get the day number (d). Which needs a bit more of an explanation.
     
    Say the diff is 108 days. The most obvious course of action is to +1 (because the starting date is day #1 and not day #0) and %15 to get 4. That's not quite right.
    Say the diff is 14 days. Smaller number. +1 is 15 and %15 is 0. That's not right: you need to get 15 and not 0. You could say "if result == 0 then result = 15" but there's an easier way:

    ($diff % 15) + 1What you're actually doing is taking the diff, +1 because of the starting date, then doing a trick where you -1 then %15 then +1. Watch:
    (14 % 15) + 1 = 15which is the result you wanted. And
    (108 % 15) + 1 = 4like before. 

    $pattern = 15; $start_date = new DateTime("2015-12-14"); // day 1 // Day 15 = 2015-12-29 $chosen_date = new DateTime("2016-03-30"); $difference = $chosen_date->diff($start_date)->days; $day_number = ($difference % $pattern) + 1; If($day_number == 13 || $day_number == 15) { Echo "possible outcome. Day $day_number."; } Else { Echo "not possible, day $day_number"; }
  15. requinix's post in Mail function not working was marked as the answer   
    There is so much more to doing emailing properly, and so many ways it can go wrong.
     
    Do yourself a favor and get yourself a copy of PHPMailer. (There are other things but it's the most popular.) There are tons of examples and plenty of documentation on how to use it, and it will take care of everything for you.
  16. requinix's post in Can PHP do all of this image manipulation? was marked as the answer   
    Using strictly PHP and GD? Well yeah, sure it's possible, but here are all the GD functions available to use and none of them do what you want. Meaning you'd have to do the edge detection* or masking yourself.
     
    Bite the bullet and use something like ImageMagick instead. It does come as a PHP extension but more commonly you invoke the command-line program. It's powerful and I'm sure it can at least do the second method, if not both.
     
    * GD can do edge detection, where it creates an image showing edges, but it won't work for arbitrary points on an image so you couldn't rely on it.
  17. requinix's post in frmvalidator.addValidation regexp for a line break? was marked as the answer   
    \r and \n are easier than the \u syntax, but they'll be interpreted by Javascript and you'll get those characters inside the actual string.
    Escape the backslashes like "\\r\\n".
  18. requinix's post in xml parse was marked as the answer   
    $entry is only an . There is no and such in it. You have to go down into the to get those.

    foreach ($xml->entry as $entry){ $Fnum=$entry->content->{'filing-type'};
  19. requinix's post in moving a file to another directory was marked as the answer   
    "The file input"?
     
    rename (which does moves too)
    Figure out the path to the file in directory A, figure out the path you want it for in directory B, and pass both to rename().
  20. requinix's post in Mail issue leads to need for complex str_replace? was marked as the answer   
    You also need to be putting $new_recipient back into the array, not the original $recipient.
     
    Another thing. Keep in mind that strpos() can return 0 if the string starts with a @. And 0 == false. So you'd get something like "@foo@xyz.com". The alternative is "@foo" (looks like an email so don't change it), which isn't good either but it would probably be better to keep that. So use === false for an exact comparison.
  21. requinix's post in Global functions in OOP with class support was marked as the answer   
    Just use a normal, plain, simple function. Like in your first example. OOP is about object entities, not about using classes for everything.
     
    The reason it doesn't work is because the "Log" that you are use-ing in Main.php does not apply to functions.php too. It's a per-file thing. So

    //functions.php use Company\Project\Handlers\Log; function __log_notice(string $text) { Log::notice(0, $text, true); }or
    //functions.php function __log_notice(string $text) { Company\Project\Handlers\Log::notice(0, $text, true); }
  22. requinix's post in Delete my Account was marked as the answer   
    Ooh, scary.
  23. requinix's post in Can you delete my account please? was marked as the answer   
    Posting something so I can mark this as solved.
  24. requinix's post in How do I delete my account? was marked as the answer   
    We don't like deleting accounts, but I can "suspend" you so your account is no longer active.
  25. requinix's post in php56 installation was marked as the answer   
    So no. 
    But the PHP Installation & Configuration forum sure sounds appropriate.
×
×
  • 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.