Jump to content

OM2

Members
  • Posts

    255
  • Joined

  • Last visited

Everything posted by OM2

  1. figured it out (i just thought it would be more complex!): for(i = 1; i < 4; i++) { random_page_index = Math.ceil(Math.random()*numberoffiles.length) - 1; random_page_selector = "random_html_code/random_" + numberoffiles[random_page_index] + ".html"; numberoffiles.splice(random_page_index, 1); // only removing one index, thus the 1 var divname = "#random_load" + i; $(divname).load ( random_page_selector, function() { $(divname).trigger("create"); } ); } thanks for the help
  2. thanks for that - that's really helpful i have coded the following (before getting your reply about how best to fill up the array): var numberoffiles = [1,2,3,4,5,6,7,8,9,10]; var random_page_index = Math.ceil(Math.random()*numberoffiles.length) - 1; var random_page_selector = "random_html_code/random_" + numberoffiles[random_page_index] + ".html"; numberoffiles.splice(random_page_index, 1); // only removing one index, thus the 1 $("#random_load1").load ( random_page_selector, function() { $("#random_load1").trigger("create"); } ); random_page_index = Math.ceil(Math.random()*numberoffiles.length) - 1; random_page_selector = "random_html_code/random_" + numberoffiles[random_page_index] + ".html"; numberoffiles.splice(random_page_index, 1); // only removing one index, thus the 1 $("#random_load2").load ( random_page_selector, function() { $("#random_load2").trigger("create"); } ); random_page_index = Math.ceil(Math.random()*numberoffiles.length) - 1; random_page_selector = "random_html_code/random_" + numberoffiles[random_page_index] + ".html"; numberoffiles.splice(random_page_index, 1); // only removing one index, thus the 1 $("#random_load3").load ( random_page_selector, function() { $("#random_load3").trigger("create"); } ); The above code is for use with jquerymobile I'm unsure how I can optimise the above I'm unsure how to use any number for the following code: $("#random_loadX").load ( random_page_selector, function() { $("#random_loadX").trigger("create"); } ); (X being the select number) Thanks in advance! OM
  3. I want to create an array of 1 - X (X could be 10, 20, 30 or any number) Then I want to randomly choose a number from 1 - X I now want to remove the random choice - and then do the same again twice Question 1: How do I create the array in the first place? Answer: var x=[0,1,2,3,4,5,6,7,8,9,10]; I'd much prefer it if I could do something like this: var x=[0...10]; This would create the same, except, I don't have to type out all the numbers! And if I needed to increase the number in the array, I could simply just change the last number I've just made the syntax up I was hoping something similar shorthand existed Or do I have to do this by creating a loop? Question 2: how do I pop an item from the middle or somewhere other than the beginning or end? I've googled and all I can find is how to remove the first and last items! The way I see it: - Get a solution for popping from the middle of an array I'm sure I'll find a solution to this if I looked - but is it optimal to be doing it this way? - Instead, maybe I could fill my array in a random order in the first place - and then just pop at the beginning or end?? Which is the best solution? Any code to start me off would be great Thanks OM
  4. oooh... that one just doesn't work! don't know why i'm not sure where i said i had something that works - perhaps i was doing a bad job of explaining myself expecting: things to match up and line up so if there are braces - i want to have them on new lines if there are tags - they should have their content indented etc looks interesting i put some html in and it didn't format nicely (ok... it's a php formatter!!!) so not fair throwing html at it i'll try php later thanks for the link
  5. i didn't reply to that point i go a bit over the top and make sure my code is all lined up perfectly it's not for my code it's for other peoples code that i want the beautifer for lets say i get a plugin for wordpress - and it's not quite working for me i like my braces to be on new lines for example - i just can't read otherwise i want a beautifier to line up everything nicely for me the online ones - they seem to be hit and miss
  6. thanks for the replies guys trying ot some of those suggestions Dan: I said I searched and couldn't find ANYTHING useful - have tried ALL (online versions) those that come in search results (first page)
  7. Can someone recommend a code beautifer Something to indent lines and format code so that it's easier to read There are a few online programs I've tried all of them and they're just not any good I'd much prefer a lightweight program on my machine Would be great if the program could handle all languages - everything from PHP to HTML to CSS Thanks in advance OM
  8. wow...! thanks i need some time to go through the code i've copied and pasted what u've given + added the new additions but am getting 2 errors for: foreach($otpl as $key => $arr){ and foreach($pivot as $row){ for both it says "invlaid argument supplied foreach()" any ideas? thanks
  9. i wasnt sure what u were saying here? is that describing a better way to code it? let me know thanks
  10. OMG erm... i don't know what to say how long did that take u to write??? probably took you 5 minutes would take ma whole day but then again... i've never used templates as u describe i'm going to have to spend time going through the code now - i'll post back here after just glancing at the code... i'm not sure about the bit where u mention about 1-11 and 12-14? i'll ask again if the code really confuses me
  11. ok, the code works a real treat. THANK YOU! the output i now get is: what i actually would prefer is something like this: much more readable that way what would be the best method of doing this? may parse twice? first time getting the other data and second time getting the item specific data (for which there could be any number) i'm thinking if i would be better to do in one loop? i think that would involve keeping track of 3 strings - the beginning, the middle part (where u have all the item_1, item_2, item_3 etc) and the end part the bit i'm not 100% sure about is how best to tie up item_1, quantity_1 and price_1 for example any ideas? thanks
  12. I've heard people say this quite often: I know 1or 2 coding languages and therefore I know them all - they're all just different langauges with different syntax The people who have said this have been fairly hardcore programmers They're saying "I can pick up a new language in zero time" How true is this? Normally... it's been ASP programmers talking about PHP or vice versa Just something that popped into my head Would be interested to hear what others say OM
  13. OMG - that looks sooo much better than my code in effect, is it doing what i proposed exactly, but in less lines of code? or is it a more optimal way? ALSO: is using preg_replace better than using the strpos is used? thanks a million ASIDE: can u recommend somewhere to learn regular expressions. i'll take ur word it that what uve done inside the pregrepalce works! i've seen some big fat books on regular expressions - which i don't fancy reading. a 4 page dummies guide would do me fine to get me started. thanks
  14. ok... that makes sense but i've been thinking... i need the _n's - these could be any number - and need to be printed out? i was thinking of doing something like this instead: foreach ($p->ipn_data as $key => $value) { if (strpos($key, 'firstname') { $body .= "\n$key: $value"; } else if (strpos($key, 'itemname_') { $body .= "\n$key: $value"; } else if (strpos($key, 'total') { $body .= "\n$key: $value"; } } (the above is simplified just to explain the point) so the above would be ok if there were itemname_1, itemname_2, itemname_3 ...... itemname_10 there would be any number of these and we'd be ok i can't think of a better solution let me know what u think EDIT: is my use of strpos OK?? i looked up in manual and this seemed to be the only choice THANKS!
  15. I've some code for an ecommerce plugin It outputs (in an email) all fields relating to the order I don't want all fields - only selected ones I wanted some advice on how to replace the current loop and also how best to compare 2 strings The code I have is: foreach ($p->ipn_data as $key => $value) { $body .= "\n$key: $value"; } This output something like this: I'm scratching my head and am not sure where to start One possibility would be to check if my chosen values that I want to output matched $key or not For this, I'd need to figure out to compare strings and get a positive if a subset of the string was contained I need to do this because of things like 'quantity_1' and 'quantity_2' I've looked at string comparison functions and can't figure out which to use OK... I think I can do it using my proposed method! But... the thing is... I would have though that was a lot of waste of CPU uneccesarily If I only wanted 5 fields and there were 10 fields, then that a potentially of 50 comparisons just to check for the $key value? Is there a better way? I'm not sure where to investigate the data - I'm not sure where the numericals get put in for something like 'quantity_1' I assume it starts life as just 'quantity_'? ANY pointers where to start would be great I know I could code a half baked solution - but I don't think it would be very optimal! Thanks OM
  16. I've been given a Wordpress theme to install by someone I've done a wingrep and checked to see if any files had 'base' in I've found a few .js files Should I be worried?? I'm attaching one of the files with this post - I'm hoping someone will look and and tell me what they think Is there an online uploader - that you can upload code files to and have them checked for malicious code?? Thanks OM [attachment deleted by admin]
  17. yes... that makes sense except, get_header() is a wordpress function i was looking for the best optimal solution
  18. thanks dan, that makes more sense the fact that get_header() spits out the contents of header.php - does not mean it has access to variables in other files in that case, i only have the choice of using a global variable?
  19. thanks for confirming the problem is with this version: <?php $myvar = true; <?php get_header(); ?> ?> $myvar doesn't seem available in header.php - get_header() puts the code of the file in the place, so i thought similar to the above the variable would be available i'm sure i'm doing something really simple wrong?
  20. I need a bit of help understanding the scope of variables If I have the following code: <?php $myvar = true; include(otherfile.php); ?> Is $myvar available for access as is in the code from otherfile.php? Specifically though, I'm trying to get my head round some Wordpress coding, so I have this instead: <?php $myvar = true; <?php get_header(); ?> ?> <?php get_header(); ?> puts the contents of header.php at this location + I'm sure it does some other things like error checking etc What is the best way to have $myvar available? The ONLY thing is I only want $myvar = true just for one file - everywhere else it should be false or not exist I'm wary of using a global variable - but if it's the only way, then I have to Thanks Omar
  21. thanks guys for the replies my first priority is to get a quick and dirty version ready that can be used it's important that there is no setup required and that the code can run standlaone the replies though have helped my thinking a lot thanks
  22. let's say i have 1000 lines - this probably won't every happen! i will have one other single file that will contain maybe 100 lines each one of the 1000 lines needs to be compared to the 100 lines in the second file to be honest: i think i'd be ok just to leave out the comparison the end purpose is to have a X number of users hopefully this will be 1000 after a few months of launch of my service does that change it in terms of required processing power? would it be wiser to have a DB in that case? actually... having said all of that, the CSV files do need to be reordered and stored as XML data the XML data needs to be stored in alphabetical order - so some sorting does need to happen let me know what u think thanks
  23. If I want to read in and process a CSV of a 1000 lines how easy is it to do without a database? By process, I mean read in the data and do simple manipulations + compare each line with a line from another file, that maybe have 50 lines I was just concerned that I might start hogging the CPU and memory of the server trying to process 1000 lines of data It's VERY important that I can do WITHOUT a database I'd only consider a database if it proves that not using will take too much CPU and memory I've only just began considering making the application - can't give full details - as I've got to figure them out myself! Any general advice would be great Thanks OM
  24. using wingrep ok... my bad... it works i thought i had tried that before - obviously not thanks a lot
  25. i tried this - didn't work though i think i must be doing something wrong the use of searches and regular expressions should be the same as used for php or perl (i assumed - hence i asked my question here) thanks
×
×
  • 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.