-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
scandir, recursive call prints an extra closing tag for xml install file
kicken replied to fero57's topic in Applications
Because of the way your function works with the recursion. Take some time to mentally step through it and you'll see. Lest assume you start it in a directory that has one sub-dir and then that dir has 1 file in it. Eg: . js/ whatever.js So when you start the code, on the first iteration the it will: $allfiles .= '<filename>'.$dir.'/'.$f; //Set $allfiles to <filename>./js if(is_dir($dir.'/'.$f)) //True { $allfiles .= "</filename>\n"; //set $allfiles to <filename>./js</filename> readFolders($dir.'/'.$f); //Start reading the new directory (see next block) } $allfiles .= "</filename>\n"; When it recurses into the next level, then it's first loop iteration will go like so: $allfiles .= '<filename>'.$dir.'/'.$f; //Set $allfiles to <filename>./js</filename><filename>./js/whatever.js if(is_dir($dir.'/'.$f)) //False { $allfiles .= "</filename>\n"; readFolders($dir.'/'.$f); } $allfiles .= "</filename>\n"; //Set $allfiles to <filename>./js</filename><filename>./js/whatever.js</filename> //Jump back up to previous level So now since it is done with that sub directory, it jumps back up to where it was in the previous function call, and continues. $allfiles .= '<filename>'.$dir.'/'.$f; if(is_dir($dir.'/'.$f)) { $allfiles .= "</filename>\n"; readFolders($dir.'/'.$f); //Jumps back to this point } $allfiles .= "</filename>\n"; //Continues to here and sets $allfiles to <filename>./js</filename><filename>./js/whatever.js</filename></filename>- 5 replies
-
- scandir
- recursive call
-
(and 1 more)
Tagged with:
-
Difference Between These 2 Percent Calculations lol
kicken replied to Monkuar's topic in PHP Coding Help
Yes. Because the other guy was having a hard time understanding the inverted logic of the other code, so he tried to make it easier to understand by renaming the variable. -
There is nothing in the code you posted that would cause duplicates in the select box, so if you are seeing them, then you have duplicates in your table, or there is some other code causing them that you have not shown.
-
You don't, you use two lines. One to include tinymce and all it's required files, and another to actually initialize the editor. By one line I meant you dont have to include all the files that come as part of the distribution, only a single .js file. You need a separate line to actually install the editor onto a textarea. For example: <script type="text/javascript" src="/path/to/tinymce.js"></script> <script type="text/javascript">tinymce.init({selector: '#textarea_id'});</script> That said if that is too much for you still, then you could take it down to a single line by creating your own .js file which will include tinymce and then install the editor onto a textarea. I've done something like this before by having a script that automatically applies tinymce to any element that has a class of wysiwyg-editor. Eg: <script type="text/javascript" src="/path/to/myfile.js"></script> ... <textarea class="wysiwyg-editor"></textarea>
-
I prefer the TinyMCE editor. The distribution consists of a lot of files, but you only need to include one to actually implement it on your page, everything else is handled automatically. Then to setup the editor it's just a single function call. If you really desire an editor with just a single file implemtation then do some googling, there is surely something out there to fit your needs.
-
For one, to compare something to NULL you have to use IS NULL or IS NOT NULL. Using = or != will not work since null is not any particular value, but rather the concept of "no value". Second, I'm not as familar with mysql anymore so not sure if it supports that type of if/else syntax. I know there is the IF() function which you'd use as SELECT IF(datetime_man IS NOT NULL, DATE_FORMAT(datetime_man,'%Y/%m/%d %H:%i:%s'), DATE_FORMAT(datetime,'%Y/%m/%d %H:%i:%s')) or, the way I do it for sql server using CASE would work also: SELECT CASE WHEN datetime_man IS NOT NULL THEN DATE_FORMAT(datetime_man,'%Y/%m/%d %H:%i:%s') ELSE DATE_FORMAT(datetime,'%Y/%m/%d %H:%i:%s') END
-
You don't prevent linking to MyPage, you prevent MyPage from loading when there is no active session. You have to add your login verification code to the top of MyPage.html (which you'd rename to MyPage.php since it now contains PHP code) and if no valid login is present, redirect the user somewhere else. With the setup you have, someone doesn't even have to login at all to view MyPage, all they need is the URL. Say someone logged in, then bookmarked MyPage, or sent the link to someone else via IM/Email. They, or whoever they sent the link to, would never have to login again in order to see that page since it is uncontrolled.
-
Assuming datetime_man is set to NULL when it hasn't been entered, then you can just use the COALESCE function. SELECT DATE_FORMAT(COALESCE(datetime_man, datetime),'%Y/%m/%d %H:%i:%s') AS datetime2 , DATE_FORMAT(COALESCE(datetime_man, datetime),'%H:%i on %d/%m/%y') AS datetime3 , SBP, SBP_R, SBP_B, DBP, DBP_R, DBP_B, HR, HR_R, HR_B, RR, RR_R, RR_B, SpO2, SpO2_R, SpO2_B, O2flow, O2flow_R, O2flow_B, O2device, O2deviceOther, TEMP, TEMP_R, TEMP_B, AVPU FROM addobs WHERE mrn='$Search' AND DATE(datetime)='$Date' AND NOT hidden = 'yes' order by datetime2 ASC");
-
Use an array where the key of the array is the call sign and the value is the number of times it has been seen. Eg: $flightCount = array(); foreach ($flights as $f){ //Assume $f['callSign'] is your ACA, SWA, N, etc if (isset($flightCount[$f['callSign']])) $flightCount[$f['callSign']]++; else $flightCount[$f['callSign']] = 1; } After the loop $flightCount would contain something like: array( [ACA] => 5 [N] => 3 [SWA] => 1 ) indicating 5 Air Canada, 3 Privates, and 1 Southwest.
-
I typically do something like this for empty tables: <table class="table table-bordered table-striped table-hover"> <tr> <th>Name</th> <th>Description</th> <th>Actions</th> </tr> {% for service in services_table %} <tr> <td>{{ service.name }}</td> <td>{{ service.description }}</td> <td> <a class="btn btn-mini btn-primary btn-block" href="{{ path('admin_edit_service', {'id':service.id}) }}"><i class="icon-pencil icon-white" title="Edit"></i> Edit</a> <a class="btn btn-mini btn-danger btn-block" href="{{ path('admin_delete_service', {'id':service.id}) }}"><i class="icon-trash icon-white" title="Delete"></i> Delete</a> </td> </tr> {% else %} <tr> <td colspan="3">No Records</td> </tr> {% endfor %} </table> If you want to omit the table entirely though then you're stuck just doing an if/else statement around the whole thing.
-
IRC bot does not detect disconnect from server, but does for local
kicken replied to gawdsed's topic in PHP Coding Help
Read up on non-blocking sockets and socket_select. Try and implement that solution and if you still have issues then post back with some updated code. You could also try enabling the SO_KEEPALIVE option using socket_set_option.- 2 replies
-
- irc
- disconnect
-
(and 1 more)
Tagged with:
-
MYSQL Selecting a rand value from the max value in a column?
kicken replied to Monkuar's topic in PHP Coding Help
Based on your description of the problem, it sounds like your query should only be returning one row which means there is no need for the MIN/MAX functions. If it does in fact return several rows though, you would need them. You can do the random bit inside the query using mysql's RAND function. For instance: SELECT FLOOR(1+(RAND()*min_dmg)) as min_dmg, FLOOR(1+(RAND()*max_dmg)) as max_dmg That would give you a random number such that 1 <= x <= min_dmg (likewise for max_dmg). Note that for both of this solution and your solution, it is possible for you to get a max_dmg number that is lower than (or equal to) your min_dmg number. Ie, you might end up with min_dmg=3 max_dmg=1 If you want to ensure that max_dmg is larger than min_dmg, you need to make min_dmg the lower bound when finding a random max_dmg. For instance: SELECT FLOOR(1+(RAND()*min_dmg)) as min_dmg, FLOOR(min_dmg+(RAND()*(max_dmg-(min_dmg-1)))) as max_dmg That would still leave the possibility of min_dmg = max_dmg but you can adjust for that also if you want to prevent it. -
Use tags when you post code. Assuming that cash is a numeric type column, then yes it is fine. The value is controlled so there is no harm in using it directly in a query. Yes.
-
The switch is comparing true to the result of the various expression. value/type of $par isn't involved in the final switch comparison. Setting $par to '' would cause it to match the first case because $par >= 0 && $par <= 2 would be true. The empty string would get converted to the integer 0 for that comparison. *side note: The above area of confusion is why I generally do not like these types of switch statements and avoid using/recommending them.
-
Whatever page your play movie button is linking to is not properly validating the session, that is why it still plays. You need to ensure all your pages (even indirect pages, such as ajax helpers) which require someone to be logged in have a check at the top of them to verify that an active login is present. If none is found, either show an error or redirect somewhere else.
-
Always do your validations BEFORE you escape the data for use in a query. That is, before you call mysql_real_escape_string or similar. Since the escape function will modify the value, there is the potential for it to turn a valid value into an invalid value. If you do your validations after, the user would get an error on their input even though as far as they can tell it meets all the requirements. Save the escaping for just prior to actually using the value in the SQL query.
-
Rather than try and get a query to give you exactly what you want, which I'm not sure is possible as the requirements are a bit odd, just order the query in ascending order and then before printing the list, move the last two items to the top. For example, in PHP: $data = $db->query('SELECT * FROM events WHERE (datetime < NOW()) ORDER BY datetime')->fetchAll(); $last2 = array_splice($data, -2); //remove the last two array_unshift($data, $last2[1], $last2[0]); //add them back to the top of the array.
-
You can always just use plain sockets and implement your server's protocol in PHP. Look at the stream_socket_client and related functions.
-
Obfuscate email - want to obfuscate specific txt instead
kicken replied to questthewordsmith's topic in Third Party Scripts
Why even bother outputting the URLs if you don't want them to be usable? If you obfuscate the URL then whatever is attempting to use it (whether it be a user browsing the source or a media player plugin) will not work properly because it wont see the correct URL. -
Switch statements are for comparing a single value, to another single value. Not for comparing ranges. If you want to do ranges you should just chain together some IF statements. if ($par >= 0 && $par <= 2){ .. } else if ($par >= 3 && $par <= 5){ ... } else if ($par >= 6){ ... }
-
How do you make a link in a infowindow on google maps?
kicken replied to frank_solo's topic in Javascript Help
Just change that bit of HTML to include your anchor tag for the link. -
You could try Tidy, it may be able to clean it up for you.
-
Requesting a particular format is generally what I do. Now days I use the new type="date" input + some JS to make it more compatible. In the past I've done separate select boxes or just a text note describing the required format. I've seen such things fairly often out on the web, even some sites that are so strict they reject a date if you don't add leading zeros (ie, 05/01/13 would be ok, but 5/1/13 would be invalid).