Jump to content

sw45acp

Members
  • Posts

    67
  • Joined

  • Last visited

    Never

Everything posted by sw45acp

  1. excellent that works fine thank you.
  2. I wrote this very simple calendar to write out the dates of a given month and year. It adds a line break at the end of each week. What I want, however, is for it to only output days that are Monday-Thursday, not Sunday,Friday, or Saturday. I would appreciate help on this matter. //january 2010 $m = 1; $y = 2010; //calculate the number of days in the month $days = date('t',mktime(0,0,0,$m, 1, $y)); //Calculate the day of the week that the month starts on $startDay = date('w',mktime(0,0,0,$m, 1, $y)); for ($i=1; $i<=$days; $i++) { //output the days with a space echo $i . ' '; //increment the startday $startDay ++; //if the start day equals seven, which is not possible because //sunday = 0, saturday =6, so we need to start a new line if ($startDay == 7) { echo '<br />'; //set start day back to zero $startDay = 0; } }
  3. ahh yes this works fine. is this re-indexing the array or just reassigning keys? $assignment as $ID => $task i only knew doing something like this was possible because of the forms that are generated in phpmyadmin.
  4. I have a form that is has a single text area for each individual school assignment. These textareas are generated by how many there are in the database. The names of the textareas are assignment[$id] with the assignment's unique id inside. It would be impossible to individually name each one because there could be more than twenty assignments. How can I go about retrieving the text in the textarea and its id to insert it into a database? Is it something like this? $assignment = array(); $assignment = $_POST["assignment"]; foreach ($assignment as $task) { $q = mysql_query("UPDATE table SET `assignment` = '$assignment' WHERE `id` = '$assignment[]'");
  5. i do mine like this to save time if (2==2){ //code }else{ //code } but if i were ever going to publish code, i would probably do it the second way
  6. Thank you for your help. I had to change the $answers to $results, and in the <span style="$style"> I changed so that way it could recognize the style. I only wanted incorrect answers in red so I put !== in the turnary operator and added the </span> before the line break. But you did the bulk of it thank you for help! $results = array("A","F","B","F","A","T","F"); $correct = array("C","F","B","T","A","T","F"); $cnt = count($correct); $output = ""; for ($i=0;$i<$cnt;$i++) { $style = ($correct[$i] !== $results[$i]) ? "color: red;" : ""; $output .= '<span style="' . $style . '">' . ($i + 1) . ') Chosen Answer: ' . $results[$i] . ' Correct Answer: ' . $correct[$i] . '</span><br />'; } echo $output;
  7. I have an array that stores the results of a quiz $results = array("A","F","B","F","A","T","F"); and an array that has the pre-defined correct results $correct = array("C","F","B","T","A","T","F"); What I want it to do is output both arrays, and highlight the differences in results in red, like so: 1) Chosen Answer: A Correct Answer: C 2) Chosen Answer: F Correct Answer: F 3) Chosen Answer: B Correct Answer: B 4) Chosen Answer: F Correct Answer: T 5) Chosen Answer: A Correct Answer: A 6) Chosen Answer: T Correct Answer: T 7) Chosen Answer: F Correct Answer: F If anybody has any ideas, I thank you muchly.
  8. ahh ok thank you guys for your help.
  9. Hi, I am trying to build a simple function that tests if certain form fields are blank. If they are, I want the form field to act as a key and the error message to be the value in an array to store the errors. However , I cant get it to append more than one value in the array. $error = array(); function process($name,$subject) { if (empty($name)) { $error['name'] = "* Name is blank"; } else if (empty($subject)) { $error['subject'] = "* Subject is blank"; } if (!empty($error)) { print_r($error); } else { echo 'no errors'; } } process("",""); it only outputs this Array ( [name] => * Name is blank ) without the subject error in there. Any help would be appreciated.
  10. This one works great. Thank you. I'm just a little confused on next and back functions on how exactly the code works there. I know with php that the ? and : means that: if x=2 ? (do this), if not : do that. Is that the same here?
  11. I added this but it after going back 2 the next button has to be clicked twice which is odd function backStep() { if (qnum == anum) { qnum -- ; anum -- ; document.getElementById("question").innerHTML = questions[qnum]; document.getElementById("answer").innerHTML = '???'; } else { qnum --; document.getElementById("question").innerHTML = questions[qnum]; } }
  12. This will work just fine! However, can we put in a back button to go back one card at a time also?
  13. I kind of just figured out a simple one. It writes to a textbox: <html> <head> <script type="text/javascript"> var stuff = new Array() var which = 0; stuff[0] = "one"; stuff[1] = "two"; stuff[2] = "three"; //previous card function prevcard() { if (which>0) { which --; theform.key.value = stuff[which]; } } //next card function nextcard() { if (which<stuff.length-1) { which ++; theform.key.value = stuff[which]; } } </script> </head> <body> <form action="" name="theform"> <input type="text" name="key" /><br /> <input type="button" name="back" value="Previous card" onClick="prevcard()" /> <input type="button" name="next" value="Next card" onClick="nextcard()" /> </form> </body> </html> However, I can't get it write to div element instead of a textbox. I am accessing it via id and using innerHTML. Can't get it to work... <style type="text/css"> div { width: 200px; height: 150px; border: 1px solid #FF0000; } </style> <script type="text/javascript"> var x = document.getElementById("mainbox"); var stuff = new Array() var which = 0; stuff[0] = "one"; stuff[1] = "two"; stuff[2] = "three"; function prevcard() { if (which>0) { which --; x.innerHTML = stuff[which]; } } function nextcard() { if (which<stuff.length-1) { which ++; x.innerHTML = stuff[which]; } } </script> </head> <body> <div id="mainbox"></div><br /> <input type="button" name="back" value="Previous card" onClick="prevcard()" /> <input type="button" name="next" value="Next card" onClick="nextcard()" />
  14. Hi, I am trying to create a very simple flash card script. Problem is, I can't find any examples on how to navigate the array containing the questions. When a person clicks next it will show the answer to the question, then next again to show the question in the sequence. I have this code so far. cards = new Array( "question 1", "answer", "question 2", "answer" ); function prevcard() { ? } function nextcard() { ? } any help you can give would greatly be appreciated!
  15. Never knew that variables could be appending like that using {}. Thank you.
  16. How can a for loop be written to write out this sentence x number of times and only increment the number after $bla by one each time? ($bla1, $bla2, etc.). But keep in mind that $bla1 and $bla2 and so on are already variables in an early script. echo (function foobar($woof,$bla1) == $something) ? "laskjflasjf $bla1" : "<s>$bla1</s>"; echo (function foobar($woof,$bla2) == $something) ? "laskjflasjf $bla2" : "<s>$bla2</s>"; I was thinking something like this: for ($x = 1; $x<=3; $x++) { echo (function foobar($woof,$bla$x) == $something) ? "laskjflasjf $bla$x" : "<s>$bla$x</s>"; } but it doesnt work because the foobar() function only allows two variables, and I think because of the fact that $bla is alreay a variable. Any help would be appreciated
  17. ok i will take a look at those. the similar_text one sounds good because it can return a percent of similarity and that easily be rounded. thank you again.
  18. Ok well thank you guys for trying. I bet it can be done somehow, but at least I have the start of the game.
  19. I put together a temporary form and it works perfectly. However, I would like help on building the other side of the game, such as a tool to kind of hack it. I would like a user to be able to input a list of words, one of them being the unknown answer. This is like a hack or a cheat for it. So if someone tested a word, it tells them the number of characters correct, and then suggests the next best answer. Here is an example, like from the fallout 3 video game. http://perl.hacker.dk/cgi-bin/fallout_hack.pl
  20. Thank you! That is excellent. I will work with this for a while.
  21. Hi! I am trying to write a function that will compare two or more words and return with the number of letters that happen to be in the same place. For example, melting and helping should return that their are 5 letters in the same place, or 5/7. The function that I have written could probably be written more efficiently. Any help would be appreciated! For some reason this returns zero instead of 5. Basically what I am trying to design is a guess game. Where you have a list of words and in that list is the correct word. You need to find it by guessing. Choosing a word will tell you how many of the characters are in the correct positions. function compare($s1,$s2) { $total = 0; if ($s1{0} == $s2{0}){ $total + 1; } if ($s1{1} == $s2{1}){ $total + 1; } if ($s1{2} == $s2{2}){ $total + 1; } if ($s1{3} == $s2{3}){ $total + 1; } if ($s1{4} == $s2{4}){ $total + 1; } if ($s1{5} == $s2{5}){ $total + 1; } if ($s1{6} == $s2{6}){ $total + 1; } echo $total; } compare("melting","helping");
  22. ok so now I understand more about them, but the thing is that my server is not apache. I do not have access to the php.ini file or htaccess file. Any ideas if this can still be done?
  23. ok thank u I will read it!
  24. hi, can anyone point me to a tutorial or something on how to set up a web page that might look like this in the url bar? i'm a real newbie at this kind of stuff. http://www.mywebsite.com/folder/ instead of http://www.mywebsite.com/folder/test.htm is that called directory indexing? for example use http://www.phpfreaks.com/forums/ there is no page extension or file extension after that. also, how to the semicolons and commas work in the url bar? are those the same as the ? in the url bar? such as in the url bar when browsing pages of this forum. again I'm a real newbie at this kind of stuff, any help would be appreciated!
  25. alright! well, thank you for all of your help. I really appreciate it.
×
×
  • 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.