-
Posts
15,223 -
Joined
-
Last visited
-
Days Won
427
Community Answers
-
requinix's post in How to simplify this JavaScript into something useable? was marked as the answer
Remember this?
expected profit = bet * odds of losing / odds of winningLet's revise that a little bit to be more clear what it means. (It was late night when I wrote that and it made sense to me.)
expected profit = bet * (odds of not winning - house edge) / odds of winningIf you predict 88 then your high roll must be within 89-99 to win. That's 99 - 88 = 11 out of 100 (or 100% - 88% - 1% = 11%). Not winning would thus be 89%. If you wager 5 and the house gets 0.96% then
expected profit = 5 * (89 - 0.96) / 11 = 40.01818Look familiar? I imagine that logic is buried somewhere in the Javascript, though it looks like they're using an alternative form that calculates gross and not net winnings. Same difference. -
requinix's post in Change date stored as epoch to datetime when altering table? was marked as the answer
I suspect doing that will try to interpret existing data as YYYYMMDDHHMMSS strings, not as Unix timestamps.
Will definitely work: add the created_at column, UPDATE it using FROM_UNIXTIME(user_date), then drop user_date. Three statements.
-
requinix's post in pattern help was marked as the answer
You aren't repeating that character set at the end.
As for the format, [0] will always be the full match. Best you can get is "i" as [1] and the identifier as [2] by using what you have now with the PREG_SET_ORDER flag.
-
requinix's post in how can a css button be used to send php post data if at all was marked as the answer
Plain HTML does not support submitting forms using links. You have two options:
a) Use a form button ( or ) and style it like the way you want. It is possible and not much more work to do since you have the appearance already working for a link.
b) Put an onclick handler on the link and cause it to submit the form. This isn't AJAX but it does require Javascript.
The first option is much better than the second.
-
requinix's post in If you don't specify a length for a data type/column, does that affect performance? was marked as the answer
Have you tried looking at the documentation?
Dates and times don't even have lengths. The string values do, sure, but the data type itself doesn't.
Lengths only matter on field types that (can) have variable length data. Like strings and numbers: for VARCHARs it is the maximum character length stored, while for *INTs it is only the display width.
-
requinix's post in Comparing Times was marked as the answer
You can compare
a) A date/time formatted as Y-m-d or Y-m-d H:i:s or H:i:s. Anything else probably won't work. The rules are complicated (I'll explain if you want) so stick to just those three formats.
b) Unix timestamps
c) DateTime objects
-
requinix's post in Updating an array held in a text file was marked as the answer
JSON would be really nice.
{ "subTitle": "Welcome to the Site" } // read $site = json_decode(file_get_contents("/path/to/file.json"), true); // write file_put_contents("/path/to/file.json", json_encode($site)); You do lose some of the PHP caching, though. To write out the array to a PHP file, use var_export.
-
requinix's post in different div is result has value more than 1 was marked as the answer
counter = 1
for each image {
if counter = 1 {
output div code with inline-block
} else {
output plain div code
}
output image code
output closing div
counter++
} -
requinix's post in Showing a thank you message after form submit was marked as the answer
The page is being refreshed because of that location.reload(), so if you don't want that to happen then don't put that code in there.
Is the .alert-success (which you should probably put an ID on rather than relying on just the class name) visible? As in it doesn't have a display:none or something? If it is, and probably should be, then you need to .show() it too.
-
requinix's post in parsing XML was marked as the answer
Inside the foreach loop you have to use $entry. $xml->entry-> will only get you stuff from the first .
-
requinix's post in json decode with foreach was marked as the answer
foreach ($output['data'] as $item){ -
requinix's post in Help with json to javascript was marked as the answer
No, you cannot return from the function. Just like you cannot use return in your original code.
Unfortunately I can't find anything good that explains how AJAX works and what you can and cannot do with it. Unfortunate because I wanted to give you something to read (preferably something that would take more than a couple minutes) before you touched any more code.
The callback function has to do a thing. It cannot return a thing. Use it to perform an action. Put the code performing an action inside the callback.
1. Why are you even using AJAX for this? Do you expect the list of users to change while the page is still open? What was wrong with the json_encode() from earlier?
2. The "callback function has to do a thing" approach will not work for that code. It's already within an event handler. Probably the most appropriate approach would be to set a variable (like but not quite how the other variables around lines 62+ are set) containing the list of users, and put that variable on line 197. But to do this best requires an answer to my first question.
-
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.
-
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; ?> -
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.
-
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.
-
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) -
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 *********/ -
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 -
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.
-
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. -
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 } -
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> -
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).
-
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')