Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Can't really tell with what you've provided. But, I notice that the showRecord() function works by checking the value of the field "record-id". If you create a new record, then the ID of that record would need to be populated into that field in order to run the showRecord() function on it. I'm guessing that has something to do with the problem.
-
Do you realize that if the opening and closing div tags are not on the same line it won't find them if you are only processing one line at a time? Plus, you have the added problem of DIV tags that are within other div tags. That is why RegEx is not a good solution for this. Plus, what if the div tag has paramters, e.g. <div class="something">? So, it would get really complicated to get a good solution with RegEx. But, based on what you are trying to do, this would work better $pattern = '/<div>(.*?)<\/div>/';
-
On the first function, the problem is in the logic when the number is not found. Look at where the "return FALSE;" is located with respect to the loop
-
No, his syntax is valid. He only omitted the quotes around the array index when used within a double-quoted string. The below is strait from the manual. But, I personally never use arrays within quoted strings without using the curly brace (in which case the quotes around the array key are necessary).
-
$mergedArray = array_merge($array1, $array2, $array3); $countedValues = array_count_values($mergedArray); print_r($countedValues);
-
Hmm, my understanding is that MySQL will automatically store the UNIX timestamp based upon the current timezone that the MySQL server is configured for. So, there should be no reason to use UNIX_TIMESTAMP() in the query. However, it is also my understanding, that MySQL will return the time also based on the current timezone. So, if I store the time of 14:00 (2PM) on a server configured in the Central Timezone (UTC - 6), the time is stored as 20:00 (8PM). But, when I return the value it will still be displayed as 14:00 because the default setting for the server is Central Time. But, I could change the locale settings before running a query to have the time returned based on any timezone I wish. That is how DBs handle dates in order to easily support multiple timezones. By using UNIX_TIMESTAMP() I think you are 'corrupting' the time. MySQL is expecting a time to be provided in the current timezone. So, in my example above, if UNIX_TIMESTAMP() was used on the value before it was saved it would modify the timestamp to 20:00 (8PM). Then, since MySQL is expecting that the timestamp is in Central time, it modifies it upon saving to 02:00 (2AM) - the next day. It would still return 8PM when retrieved since it thinks that's the time in the current timezone. But, based on what the server's timezone is set for and the time of day you are running your tests, this could explain the discrepancy. So, save the values without UNIX_TIMESTAMP(). If you need that value, then use it on the values when retrieving them.
-
Here's a quick example <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function(){ var totalSeconds = 100; var timestamp; var endTime; $("#buttonClick").on('click', function(){ timestamp = new Date(); endTime = timestamp.getTime() + (totalSeconds * 1000); var timer = setInterval(function () { timestamp = new Date(); $("#countdown").text(Math.round((endTime - timestamp.getTime()) / 1000)); if(secondsLeft<=0) { clearInterval(timer); } }, 1000); }); }); </script> </head> <body> <button id="buttonClick">Click Me</button> <div id="countdown">100</div> </body> </html>
- 2 replies
-
- javascript
- html
-
(and 3 more)
Tagged with:
-
Why would you expect a program to continue to run when you put a phone to sleep? That would kind of defeat the purpose of putting a device to sleep, wouldn't it? The solution is to change your logic to be based off a timestamp. That way once the counter starts up again it will know how many seconds have passed.
- 2 replies
-
- javascript
- html
-
(and 3 more)
Tagged with:
-
What do you mean by it's "not working"? That function is only returning the same value that is passed to it. Just because you named the function "encrypt_password" doesn't mean it will magically do something to the value if that is what you are expecting. If it was that easy I would create the following function: function returnWinningLotteryNumbers($date) { return $numbers }
-
Populating a dropdown from SQL Server db is not populating?
Psycho replied to kelechi's topic in PHP Coding Help
I don't use MS SQL with PHP. Are you sure that your query isn't failing and that it it properly constructed such that there would be records? -
if ($_POST["taal"] == "ICT") { echo ("ICT-opleidingen zijn vol. Kies een andere opleiding."); } elseif { echo ("Uw opleiding: ") . $_POST["OG"]; } An elseif() statement requires a condition. Perhaps you meant to use just an else statement Do this: if($foo == 'one') { //Do something } elseif ($foo == 'two) { //Do something else } Or this: if($foo == 'one') { //Do something } else { //Do something else }
-
Populating a dropdown from SQL Server db is not populating?
Psycho replied to kelechi's topic in PHP Coding Help
I don't see an opening <select> tag in your code. Plus, option tags don't have a name attribute. Also, it is better to build (the necessary) html in your code and output it later. This helps to separate the logic from the output <?php $tsql = "SELECT bids.BidType +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY bids.BidType UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid where status.status='Open' GROUP BY status.status UNION SELECT status.status +'[' + CAST(COUNT(*) as varchar)+ ']' solicitationName FROM bids INNER JOIN status ON bids.Bidstatus = status.statusid GROUP BY status.status"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "Error in executing query.</br>"; die( print_r( sqlsrv_errors(), true)); } $solicitationOptions = ''; while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) { $solicitationOptions .= "<option value=\"{$row['solicitationName']}\">{$row['solicitationName']}</option>\n"; } //Perform ALL logic needed for the page - then output the HTML ?> <html> <head></head> <body> <select name=""> <?php echo solicitationOptions; ?> </select> -
large bulk insertion in mysql problem
Psycho replied to farazch's topic in PHP Installation and Configuration
Can you post the contents of the CSV file from lines ~130 to ~140? Where are these CSV files generated from. You state there is no error, but simple things (missing comma for instance) can easily be missed. If these files are all coming from the same source process, there could be an error in that. -
Check this var_dump($monthnum); Or, better yet, echo $patientsbirthday to the page.
-
Having fields show if only checkbox is checked
Psycho replied to laflair13's topic in PHP Coding Help
Then, put the value in a span or div and set the display accordingly -
As mac_gyver stated,t eh problem is the fact that you are saving the entire results from str_get_html() here $data[] = $html; That is a HUGE object of data. You need to parse the results of $html to the data you need and save that to the array.
-
Without knowing how your code is structured, it's kind of hard to give any definitive answers. I suspect you are creating new variables (or array indexes) or appending to variables on each iteration. If you define a value on an iteration of the loop and don't need it on subsequent loops, then unset it. Writing to a file could help - depending on what you are actually doing. But, I have a hard time believing that the data on an external page is so large that it would cause this problem. You likely have some unnecessary inefficiency in your process that is the root of the problem.
-
That last one seems to be working for me. The if() condition is returning false as the string does not contain any characters outside the ones contained in the regular expression. Although that can be cleaned up a bit by using the \w wildcard which includes a-z, A-Z, 0-9 and _ (underscore). <?php $_POST['title'] = '42" AJ Slick'; if(preg_match('#[^\w\-\,\!\?\+\"\'\ \.]+#',$_POST['title'])) { echo "error"; $err[]='<p class="error" style="color: #ed1c24;">Your Title contains invalid characters!</p>'; } else { echo "OK"; } //Output: OK ?>
-
Using IPs is never a good way to determine unique users. Many users can be using the same public IP address (behind a router), so you would be blocking users because one other user made a vote. Conversely, if someone want to vote multiple times it can be pretty simple to get their IP changed. The best method is if you have login to ensure the same user cannot vote twice.
-
Need Help generating an answer for a guessing game
Psycho replied to Harasume's topic in PHP Coding Help
@Harasume, I looked at the assignment, but not the attached files. The assignment has some pretty specific requirements that can each be done iteratively. Don't look at the problem as a whole, define the smallest possible functions and tackle those one at a time . So, take one step at a time. If you run into problems, post the code relevant to what you are working on and what you problem is. As you get one thing working move on to the next. Here would be my suggestion: 1. Create the form and ensure you can post it 2. Use the two arrays to populate the select list 3. Pick a random entry to generate the question 4. Determine how will "remember" the question and the user's answer when the form is posted 5 Create the logic to increment the wrong answers or determine that the right answer was selected EDIT: The instructions give you the code to pick a random state to use for the quiz $state = $states[ mt_rand(0, count($states)-1) ]; You just need to use a session value. If the selected state value in the session exists, then the user already initiated the test. If not, you need to generate the value using the code above if(isset($_SESSION['state'])) { //User already started the test, test the posted value to the session value //And perform steps to increment counter and show correct message //If answer is correct - unset the session value } else { $state = $states[ mt_rand(0, count($states)-1) ]; $_SESSION['state'] = $state; } -
Need Help generating an answer for a guessing game
Psycho replied to Harasume's topic in PHP Coding Help
Yeah, but he's not asking you to correct his grammar now is he. -
Having fields show if only checkbox is checked
Psycho replied to laflair13's topic in PHP Coding Help
Then I will ask again, did you even try the code I provided? It does exactly what you are asking. The page has two forms - one simulates what the administrator will see and the other simulates what the user would see. Make changes to the admin form and submit the page and you will then see how those changes are reflected in the user form. -
Having fields show if only checkbox is checked
Psycho replied to laflair13's topic in PHP Coding Help
Did you even try the code I provided? You state The statement of "show on frontend" would seem to indicate that the checkbox is not displayed to the user, but for some sort of administrator. If that is the case, then I think the code I provided illustrates that functionality. If that is not the case, then what is your expectation of the user experience? If the field it empty and the checkbox is unchecked, what happens when the user checks the checkbox? There's no value, so the field would still not display based on your requirements. And, if your expectation is that the end user will be checking/unchecking this field then you want JavaScript - not PHP. -
Having fields show if only checkbox is checked
Psycho replied to laflair13's topic in PHP Coding Help
OK, I *think* I know what you are trying to accomplish. You have in essence two forms. One for the admin and one for the user. You want the admin to be able to edit the values and/or determine if the field is displayed to the user. Try out this working example <?php session_start(); //Set values passed via post //This demo uses session vaues instead of a DB if($_SERVER['REQUEST_METHOD']=="POST") { //Set values in session vars (simulate doing an UPDATE query) $_SESSION['manufacture'] = trim($_POST['manufacture']); $_SESSION['manufactureCheck'] = isset($_POST['manufactureCheck']) ? 1 : 0; $_SESSION['model'] = trim($_POST['model']); $_SESSION['modelCheck'] = isset($_POST['modelCheck']) ? 1 : 0; } //Get the 'saved' values (simulate a SELECT query) $manufacturerValue = $_SESSION['manufacture']; $manufacturerCheck = $_SESSION['manufactureCheck']; $modelValue = $_SESSION['model']; $modelCheck = $_SESSION['modelCheck']; //Determine if fields should be displayed based on whether they //have a value and if the corresponding checkbox is checked $showManufacturer = ($manufacturerCheck & !empty($manufacturerValue)); $showModel = ($modelCheck & !empty($modelValue)); ?> <html> <head> </head> <body> <b>Admin Form</b> <form action="" method="POST"> <div class="form-group"> <label class="col-md-3">Manufacture</label> <div class="col-md-8"> <input type="text" name="manufacture" value="<?php echo $manufacturerValue; ?>" class="form-control" /> </div> <!-- /.col --> <input type="checkbox" name="manufactureCheck" value="1" <?php echo ($manufacturerCheck) ? ' checked="checked"' : ''; ?>> <span style="">Check to show</span> </div> <!-- /.form-group --> <div class="form-group"> <label class="col-md-3">Model</label> <div class="col-md-8"> <input type="text" name="model" value="<?php echo $modelValue; ?>" class="form-control" /> </div> <!-- /.col --> <input type="checkbox" name="modelCheck" value="1" <?php echo ($modelCheck) ? ' checked="checked"' : ''; ?>> <span style="">Check to show</span> </div> <!-- /.form-group --> <button type="submit">Submit</button> </form> <br><br><br><br> <b>User Form</b> <form action="" method="POST"> <?php if($showManufacturer) { ?> <div class="form-group" style="display: <?php echo $manufacturerStyle; ?>;"> <label class="col-md-3">Manufacture</label> <div class="col-md-8"> <input type="text" name="manufacture" value="<?php echo $manufacturerValue; ?>" class="form-control" class="form-control" /> </div> <!-- /.col --> </div> <!-- /.form-group --> <?php } ?> <?php if($showModel) { ?> <div class="form-group" style="display: <?php echo $modelStyle; ?>;"> <label class="col-md-3">Model</label> <div class="col-md-8"> <input type="text" name="model" value="<?php echo $modelValue; ?>" class="form-control" /> </div> <!-- /.col --> </div> <!-- /.form-group --> <?php } ?> </form> </body> </html>