Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. There is no viable reason why you would receive different results on different browsers. PHP is server side, and sends the same output to all browsers. It doesn't even know what browser you have, (unless the browser specifically sends that info). Lets look at the logic. 1. Get seen snippets. 2. Set snippets to an empty array. 3. Get the array keys of the empty snippets array (unSeenSnippets). 4. If there are indexes in the seenSnippets array, then get the difference between the seenSnippets array, and the empty unSeenSnippets array. 5. Now get a random index from the unSeenSnippets array, which will be empty unless you have something in the seenSnippets array. 6. Now you ask for the random index, which may be empty, to find the snippet.
  2. You should separate logic and output. So all of your processing should go ahead of your HTML. This is what you are talking about, and the most logical way of coding in PHP. <?php //set your variables: if(isset($var)) { $var = 'This variable has been set!'; } else { $var = 'This variable has not been set!'; } ?> <html> <body> <?php echo $var; ?> </body> </html>
  3. The temp folder is suppose to empty when the program finishes, or in the case of PHP, when the script ends. So if you don't move it, before the script ends, the file stored in the temp directory is lost. You could move it to an image location, then if their account is flagged inactive for a specific amount of time, you could unlink the image.
  4. Well, try looking at it like: foreach($array as $index => $value) {
  5. I would think that if it is a PHP file, it would need to be a .php file! Unless you told the server to parse .htm files as PHP.
  6. Here is an old function of mine. It tends to drop an hour under certain circumstances, although I never wasted time trying to track it down. This function attempts to track leap years also. Now, there may be a more current way of doing it easier, but this function has already been written. You are welcome to use it. <?php //set real dates for start and end, otherwise *nix the strtotime() lines. //$return 'days' will return days/hours/minutes/seconds. //$return 'hours' will return hours/minutes/seconds. //$return 'minutes' will return minutes/seconds. //$return 'seconds' will return seconds. function timeDifference($start,$end,$return='decade') { $ex = explode('-',$start); $sm = ($ex[1] < 10) ? (int)substr($ex[1],1,1) : (int)$ex[1]; $sy = (int)$ex[0]; $en = explode('-',$end); $em = ($ex[1] < 10) ? (int)substr($ex[1],1,1) : (int)$ex[1]; $ey = (int)$ex[0]; $months = array(1 => 2678400, 2=>2419200, 3=>2678400, 4=>2592000, 5=>2678400, 6=>2592000, 7=>2678400, 8=>2678400, 9=>2592000, 10=>2678400, 11=>2592000, 12=>2678400); $lyears = array(2000,2004,2008,2012,2016,2020,2024,2028,2032,2036,2040, 2044,2048,2052,2056,2060,2064,2068,2072,2076,2080,2084, 2088,2092,2096); $start = strtotime($start); $end = strtotime($end); $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'decade': $dy = $sy; $decade = NULL; for($i = 1; $i <= 10; $i++) { @$dyear += (in_array($dy,$lyears)) ? 31622400 : 31536000; ++$dy; } $decade = floor($difference/$dyear); //echo '<br/>' . $difference . '/' . $dyear . '='; $difference = $difference % $dyear; //echo $difference; $time['decade'] = $decade; case 'year': $ty = $sy + 1; $tm = $sm; $year = NULL; while($difference >= 31536000) { @$tyear = (in_array($ty,$lyears)) ? 31622400 : 31536000; if($difference >= $tyear) { @$year++; //echo '<br/>' . $ty . ' = ' . $tyear; $difference = $difference - $tyear; } ++$ty; } $time['year'] = $year; case 'month': $month = NULL; // $m = ($m == 12) ? 1 : ++$m; while($difference > 2419200 || (!in_array($sy,$lyears) && $sm == 2 && $difference == 2419200)) { if(in_array($sy,$lyears, true) && $sm === 2) { @$month += ($difference >= 2505600) ? 1 : 0; //echo '<br/>' .$sm . '-' . $sy . '=2505600'; $difference = ($difference >= 2505600) ? $difference - 2505600 : $difference; } else { @$month += ($difference >= $months[$sm]) ? 1 : 0; //echo '<br/>' . $sm . '-' . $sy . '=' . $months[$sm]; $difference = ($difference >= $months[$sm]) ? $difference - $months[$sm] : $difference; } $sy = ($sm == 12) ? ++$sy : $sy; $sm = ($sm == 12) ? 1 : ++$sm; } //echo '<br />' . $difference; $time['month'] = $month; case 'week': $week = floor($difference/604800); $difference = $difference % 604800; $time['week'] = $week; case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['day'] = $days; case 'hours': $hours = floor($difference/3600); $difference = $difference % 3600; $time['hour'] = $hours; case 'minutes': $minutes = floor($difference/60); $difference = $difference % 60; $time['minute'] = $minutes; case 'seconds': $seconds = $difference; $time['second'] = $seconds; } if(is_array($time)) { if($start > $end) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } return $value . ' ' . $key . ' '; } } } elseif($end > $start) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } @$output .= $value . ' ' . $key . ' '; } } } } return $output; }
  7. There is no way for PHP to execute a file, the server has to execute files, the PHP parser is just waiting for the server to send it a file to parse. What you are asking is what the Cron Daemon was designed to do. However, instead of having 50 Cron's running, just create a PHP file to do what you need, then tell Cron to run that file every minute.
  8. Don't run queries in loops. It will turn into a nightmare. Un-Tested added to Psycho's code SELECT rooms.roomID, rooms.roomDescription, roomsbooked.event_date FROM rooms LEFT OUTER JOIN roomsbooked ON rooms.roomID = roomsbooked.roomID AND roomsbooked.event_date BETWEEN '$startDate' AND '$endDate' WHERE roomsbooked.roomID IS NULL ORDER BY roomsbooked.event_date
  9. Why not just let MySQL do everything? Something like: Un-Tested REPLACE INTO tbl_Attributes (Part, Model) SELECT b.A,a.Model FROM TempAttributes AS b JOIN tbl_Root AS a ON SUBSTR(b.A,0,4) = a.Root GROUP BY b.A Not saying it will work without tweaking, but it is worth a shot.
  10. Try: SELECT o.QuestionId, o.Answer AS Answer1, t.Answer AS Answer2 FROM tblquestion_mc AS o JOIN tblquestion_default AS t ON o.QuestionId = t.QuestionId WHERE o.QuestionId IN ($idList);
  11. You really only have to calculate between the current date, and the end date to find the number of days left. SELECT DATEDIFF(Final Date,CURDATE()) AS days FROM table WHERE id = 1 Assuming of course that your columns are valid date type columns.
  12. I use getimagesize.
  13. You probably will not get any help here, as most of us will view a sites TOS before helping scrape the pages: NHL TOS
  14. You need to find the error: mysql_error.
  15. You may be able to use SUBSTRING(), but I have never tried it in that context.
  16. Why do you have HTML code inside of an image? The only thing that should be in your code is:
  17. You should also have unique id names. If you are only using the id for styling, then use a class. If you are using it for an anchor or other location sourcing, make the names unique. http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
  18. The second argument to the date function is a UNIX timestamp. So that date returns that time, rather than the current. There is a couple of options you can run with. 1. You can specify the date like you are doing. 2. You can store a UTC date in MySQL using the timestamp column type, and specify it to default to CURRENT_TIMESTAMP, you will not have to send anything, and it will add the timestamp. Like Davidannis says, date is a reserved keyword in MySQL, so you will need to enclose it in backticks(`). Edit: UNIX on the brain...
  19. You should look into ON DUPLICATE UPDATE. Making sure that you have a primary, or unique key.
  20. Next time I'll check that "1 reply added" message. $startTime = strtotime($appsCheck->jobIntStTime); $finishTime = strtotime($appsCheck->jobIntFiTime); for($i = $startTime; $i <= $finishTime; $i+=900) { $date = date('H:i', $i); $times .= "\t\t<option value=\"{$date}\">{$date}</option>\n"; }
  21. You should be checking $_SERVER['REQUEST_METHOD'] http://php.net/manual/en/reserved.variables.server.php to see if the form is submitted.
  22. Members area? restricted access? This is really a personal taste thing. AS you can put it anywhere you want to. Some people opt to put it above the public HTML folder (htdocs), others prefer to put it inside of the public directory and .htaccess deny anyone from using it. Still others just let their log in system handle all of the security (must be very robust). All in all, it is your decision.
  23. <?php if(!user_registerd) { //if user is not registered echo $link; } ?>
  24. You don't connect to the database through flash, but you can through PHP. What is going to happen, is flash is going to request data from a script, that script returns the data in some form (text,xml,html), and then you let AS3 sort and display that data how you desire. Take a look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
  25. Are you getting "out of sync" errors? IF so, you need to do one of 3 things: 1. store the result: 2. finish using the results before you make another database call: 3. close the result:
×
×
  • 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.