jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
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.
-
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>
-
Where to start to make a very basic page maker/editor?
jcbones replied to MrTIMarshall's topic in PHP Coding Help
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. -
Well, try looking at it like: foreach($array as $index => $value) {
-
change html code content by time with php. possible?
jcbones replied to bk1984bgl's topic in PHP Coding Help
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. -
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; }
-
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.
-
MySQL select where record does not exist in other table
jcbones replied to john-formby's topic in PHP Coding Help
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 -
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.
-
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);
-
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.
-
Best way to get file mime-type/extension
jcbones replied to mostafatalebi's topic in PHP Coding Help
I use getimagesize. -
You probably will not get any help here, as most of us will view a sites TOS before helping scrape the pages: NHL TOS
-
You need to find the error: mysql_error.
-
You may be able to use SUBSTRING(), but I have never tried it in that context.
-
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...
-
You should look into ON DUPLICATE UPDATE. Making sure that you have a primary, or unique key.
-
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"; }
-
You should be checking $_SERVER['REQUEST_METHOD'] http://php.net/manual/en/reserved.variables.server.php to see if the form is submitted.
-
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.
-
How can I hide a menu item from a registered user?
jcbones replied to MrSamCraft's topic in PHP Coding Help
<?php if(!user_registerd) { //if user is not registered echo $link; } ?> -
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
-
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:
- 5 replies
-
- php
- prepared statements
-
(and 1 more)
Tagged with: