Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. For instance, if my maths is correct, with 6 jobs there are 720 (6!) possible ways of matching a machine with a job. The way i'd tacke this would be to first produce a function which works out the different possibilities (e.g. 1234,1243,1324,1342,1423,1432 etc), the check the time taken for each of these to find the lowest.
  2. Any table up to 6 jobs and machines? With such a limited number, i'd just check every possibility.
  3. It depends on the style of your game too. I'd probably go for pixel art, but as i say, it depends on the style you're after.
  4. The problem is that you're sending some data to the browser prior to the session_start() function, which you cannot do. This could be just whitespace - for instance, if you're opening php tag is after any whitespace character, you will get this error. Check this thread: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html
  5. Indeed. Try: $query = "SELECT count(*) FROM gallery WHERE category = '$current_category'"; Unlike php, the comparison operator in mysql is a single = sign. Also, whenever you have a problem with a query, try adding an or die statement: $result = mysql_query($query) or die(mysql_error().'<br />Query was: '.$query);
  6. You're going to have to come up with some form of algorithm based on what units each person has. This could be very simple - say a person has 5 soliders with a power of 1 each and 2 tanks with a firepower of 2 each. Total firepower = 5*1 +2*2 = 9. Other user has 4 soldiers and 3 tanks. Total firepower = 4*1 + 3*2 = 10. User two destroys user 1. However, its unlikely your game would be very good with such a simplistic battle. You'd want to take into account factors such as which units are better against what, who is defending, speed of units etc. You'd also probably want to consider the idea that you dont destory all of either team at first, but rather destroy some of their units. In short, its as complex as you want it to be.
  7. The only way i can think is to go through character by character, and create a new string with only the numeric characters: <?php $product_model = "S820D"; $num = ''; for($x=0;$x<strlen($product_model);$x++){ if(is_numeric($product_model[$x])){ $num.=$product_model[$x]; } } echo $num; ?>
  8. Try using: $link = strtolower(date('M',$time)); You'll find all the formatting characters you need here: www.php.net/date I also used to the strtolower function to make all the characters lower case.
  9. You made a little mistake when copying my post. Change this line: $link = date('MY'); to: $link = date('MY',$time); Without the second parameter, the date function will return the formatted string for the current date, hence the reason why the value was always sep2007 (well, it would be till we get to october anyway!)
  10. Still does't help you find the term in the first place! And yes, you will want some error checking on the page number. Indeed, you'll want some on all of the variables you're getting from the user. At present, you're querying your database with information straight from the user, which is a large security risk. Consider using the mysql_real_escape_string() function on user data.
  11. I expect register_globals is turned off (which is a good thing) and so $page is undefined. Try changing the top of your script to: <?php include 'connect.php'; $c_loc = $_GET['cam']; $t_loc = $_GET['tape']; $page = $_GEt['page']; Edit: And yes, the reason for the large number of topics on the subject is simpy because until you've done it, you wouldn't know what it's called - people seem to forget that.
  12. Indeed. But what happens when you get people who dont use punctuation? Edit: Whoops. Didn't read your post properly. Perhaps that would be a better solution.
  13. Well, im no CSS expert, but as far as i'm aware, !important isn't recognised by IE, hence why it's used as a 'hack' to place things properly in IE and other browsers - so you'd still have problems for anyone (e.g. most people) viewing in IE.
  14. Hmm, i wonder if you could first remove all <p> tags, then put them back in at each line break? Not sure if that would work in practice...just an idea.
  15. Well, if you changed the value of the option to: <?php echo '<select name="month">'; for($x=0;$x<12;$x++){ $time = strtotime("$x months ago"); $month = date('F Y',$time); $link = date('MY',$time); echo '<option value="'.$link.'">'.$month.'</month>'; } echo '</select>'; ?> And submitted the form with GET then yes, it would work.
  16. I'd probably just show the first few words of a given article, which could be achieved by exploding by a space, and echoing the first few words. For example: <?php $str = 'Here is my news arcticle that i only want to show the first few words of'; $num_words = 3; $words = explode(' ',$str); $i = 0; $teaser = ''; while($i<$num_words){ $teaser .=' '.$words[$i]; $i++; } echo $teaser; ?> You'd then include a link after that to read the whole article.
  17. You'll want regular expressions: <?php $str = 'é'; if(!eregi('^[A-Z]+$',$str)){ echo 'bad string'; }else{ echo 'good string'; } ?>
  18. How about: <?php echo '<select name="month">'; for($x=0;$x<12;$x++){ $time = strtotime("$x months ago"); $month = date('F Y',$time); echo '<option value="'.$x.'">'.$month.'</month>'; } echo '</select>'; ?>
  19. It is indeed javascript. And it's also randomize not randomate. Anyways, this little bit should do it for you: rand = Math.floor(Math.random()*47+1); randomized = pos[rand]; So the variable randomized will contain the element you want.
  20. Edit: unfortunately, i can't get the integral symbol to display, so im using f to represent it. Eugh, well im a bit stuck with some integration by parts. I was beginning to get it, but i've some unstuck with problems similar to: f (x/(x-1)^2) dx The way ive gone about it is to let u=x and let dv/dx = (x-1)^2 So, du/dx = 1 and v = -(x-1)^-1 Therefore, given the formula uv - f (v*du/dx) , i thought the answer should come about something like: -x(x-1)^-1 - f(-(x-1)^-1). This is where the problem comes in. Im not entirely sure how to integrate this part. I thought it might be -ln(1-x), but im not completely sure. For reference, the answer in the back is ln(x-1) - x/(x-1) Ill completely understand if i get no replies here, but im rather confused and would appreciate a pointer. I suspect im doing somethinga bit stupid somewhere, but im not sure what. Thanks in advance if anyone does reply!
  21. Indeed. You'll first need to get information from the website either with file_get_contents or with cURL (using file_get_contents() will be easier, unless specific headers need to be sent to the site). As rarebit mentioned, you'll then need to find the relevant information using regular expresions.
  22. In what way does it not work? What happens when you run the code? I know it may sound obvious, but i take it you are also echoing a table tag somewhere?
  23. In response to your original question of counting the number of elements within your multidimension array, this should work: <?php $array = array(1,2,array(1,2,3,array(1,2,3)),3,4,array(array(array(1,2)))); echo '<pre>'; print_r($array); echo '</pre>'; function count_array($array){ $num = 0; foreach($array as $v){ if(is_array($v)){ $num += count_array($v); }else{ $num++; } } return $num; } echo 'number of items in your array: '.count_array($array); ?>
  24. How about this: <?php function no_of_files($start_dir,$sub_dir=FALSE){ $no_of_files=0; if($sub_dir === false){ $handler = opendir($start_dir); }else{ $start_dir = $start_dir.$sub_dir; $handler = opendir($start_dir); } while(false !== ($file = readdir($handler))){ if($file != '.' && $file != '..'){ if(is_dir($start_dir.'\\'.$file)){//if this is a directory, recall the function with the subdirectory defined $dir_name = '\\'.$file; echo $dir_name.'<br />'; $no_of_files += no_of_files($start_dir,$dir_name); }else{//is a file, so increase our counter $no_of_files++; } } } return $no_of_files; } echo no_of_files('C:\Documents and Settings\Ben\My Documents\My Music'); ?> I made it for a post a while back. Counts the number of files in any directory and all sub directories.
  25. mysql_result is slower than mysql_fetch_assoc (according to w3schools), and its about the same amount of coding. Please don't answer my question with another question. Haven't you ever heard of the Socratic Method? Thats just rude jesi, you asked another question! Shock horror!
×
×
  • 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.