Search found 20 matches

by MrRSMan
Fri Jun 18, 2010 6:35 pm
Forum: PHP - Code
Topic: >NET programmer needs a PHP file interpreted
Replies: 5
Views: 308

Re: >NET programmer needs a PHP file interpreted

Building on what McInfo said, it seems to also automatically altar files in a pre-defined way, rather than simply allowing somebody to do in manually. I suggest firstly removing it from your server ensuring that you do not visit the page in a browser. Secondly, it's probably not a great idea to have...
by MrRSMan
Thu Jun 17, 2010 1:27 pm
Forum: PHP - Code
Topic: PHP Beginner
Replies: 4
Views: 387

Re: PHP Beginner

For #1, you simply need to catch the value entered, $dollars, and then do some simple maths- dividing by 50, 20, 10 and so on. Using if/else allows you to only continue if the value is greater than 0. $dollars = $_POST["dollars"]; if($dollars <= 0){ echo"Negative amount entered";...
by MrRSMan
Mon Jun 14, 2010 12:09 pm
Forum: PHP - Code
Topic: Sorting a multidimensional array
Replies: 12
Views: 871

Re: Sorting a multidimensional array

Sorry about this, but say in here: function my_sort_string($a,$b) { if ($a[1] == $b[1]) { return 0; } return ($a[1] < $b[1]) ? -1 : 1; } ...I wanted to make the index variable. How can I achieve something like this? $index = 1; function my_sort_string($a,$b) { if ($a[$index] == $b[$index]) { return ...
by MrRSMan
Mon Jun 14, 2010 11:48 am
Forum: PHP - Code
Topic: Sorting a multidimensional array
Replies: 12
Views: 871

Re: Sorting a multidimensional array

Thanks Andy- I think this is just what I need. I'm going to have a play around a drop this into my code- will get back if I need additional help, if you don't mind :)
by MrRSMan
Mon Jun 14, 2010 11:05 am
Forum: PHP - Code
Topic: Sorting a multidimensional array
Replies: 12
Views: 871

Re: Sorting a multidimensional array

http://us2.php.net/array_multisort ('Sorting database results' section) Thank you Weirdan, but I've already been looking at this and can't make it work. Your definition of your main array "nation" is a bit odd...Did you mean something like this? $nations = array(   "Nation_One" ...
by MrRSMan
Mon Jun 14, 2010 10:28 am
Forum: PHP - Code
Topic: Sorting a multidimensional array
Replies: 12
Views: 871

Sorting a multidimensional array

I have the following array: $arr = array($nation => array($var1, $var2), $nation => array($var1, $var2), $nation => array($var1, $var2)); I'm using foreach to loop through $nation and for each instance echo $var1 and $var2. What I now want to do is sort instances of $nation by the order of $var1. Fo...
by MrRSMan
Mon Jun 14, 2010 5:11 am
Forum: PHP - Code
Topic: Foreach loop through array
Replies: 2
Views: 122

Re: Foreach loop through array

Thanks Amargharat- massive help and much appreciated :)
by MrRSMan
Mon Jun 14, 2010 5:11 am
Forum: PHP - Code
Topic: Populating an array
Replies: 2
Views: 110

Re: Populating an array

Thank you internet-solution- your code worked perfectly :)
by MrRSMan
Sun Jun 13, 2010 7:35 pm
Forum: PHP - Code
Topic: Foreach loop through array
Replies: 2
Views: 122

Foreach loop through array

I have an array with the following structure: $arr = array($nation => array($var1, $var2), $nation => array($var1, $var2), $nation => array($var1, $var2)); I want to loop through $nation and for each instance echo $var1 and $var2. I've been trying dozens of foreach loops and nothing has worked. I ho...
by MrRSMan
Sun Jun 13, 2010 4:26 pm
Forum: PHP - Code
Topic: Populating an array
Replies: 2
Views: 110

Populating an array

I have a foreach loop which simply echoes several variables. What I want to do now is populate an array with these variables. My code is as follows: foreach($nations as $nation){ print($var1); print($var2); } I would like these vars arranged in a multidimensional array with the structure as follows:...
by MrRSMan
Sun Jun 13, 2010 9:39 am
Forum: PHP - Code
Topic: Redeclaring a function
Replies: 4
Views: 179

Re: Redeclaring a function

Benjamin thank you very much- you've just put an end to 2 days of head scratching and failed solutions. I've just tested what you said and it worked perfectly- your help is hugely appreciated.

Cookies for Benjamin :)
by MrRSMan
Sun Jun 13, 2010 8:31 am
Forum: PHP - Code
Topic: Redeclaring a function
Replies: 4
Views: 179

Re: Redeclaring a function

Okay my code is fairly simple I think. I'm using an XML parser (which works fine), but want to run it for every instance of $nation. $nations = array("standica", "alecstonia"); foreach($nations as $nation){ //XML parser start $uFile = "http://www.nationstates.net/cgi-bin/reg...
by MrRSMan
Sun Jun 13, 2010 6:18 am
Forum: PHP - Code
Topic: Redeclaring a function
Replies: 4
Views: 179

Redeclaring a function

I'm trying to use foreach to pass $var to foo(), and I get "Fatal error: Cannot redeclare foo()". I understand why I'm getting this error since PHP does not allow you to declare a function more than once, but this is exactly what I need to do. Can I make foreach somehow "wipe clean&qu...
by MrRSMan
Thu Oct 29, 2009 7:40 pm
Forum: PHP - Code
Topic: This should be really easy to answer, honest
Replies: 2
Views: 383

This should be really easy to answer, honest

I'm using the code below to check for if a certain table exists in a MySQL database. The code works perfectly as it is by the way. What I want to do is too allow people to check for table of their choice, by way of a form. So basically I just want to substitute $table for $var. How do I do this? <?p...
by MrRSMan
Wed Oct 28, 2009 5:04 pm
Forum: PHP - Code
Topic: preg_match square brackets
Replies: 4
Views: 734

Re: preg_match square brackets

pickle wrote:Escape them with "\"
Could you show me the code please? I' think I've tried this and it didn't work- or maybe I just got it wrong.