Jump to content

Richard_Hollenbeck

New Members
  • Posts

    9
  • Joined

  • Last visited

Richard_Hollenbeck's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks to both of you. mac_gyver, your help is awesome as it always has been. Both of the first two answers work perfectly. However, now that Josh posted another reply that sorts the whole array: I am even closer to where I need to go than I ever anticipated. You both gave the best answer, but I can only vote on one "best answer." So I have to pick this one for the additional sort. Thanks to you both!
  2. I am NOT looking for max(). In an array, I'm trying to find the key with the highest value, not the highest value itself. For example, $arr = array(15, 10, 25, 419, 65, 25); echo max($arr); // Nope. Not what I'm looking for. Wrong answer. echoes the value 419. I know. Thanks. That's not what I want. We all know that in the above example, $arr[3]==419. I got that. But I am not looking for the 419. I'm looking for the 3. Thanks for any help.
  3. Thanks. I was wondering about that. Why run a loop when I am going directly to the only record I need? Great. kicken, on 21 Nov 2013 - 8:56 PM, said:
  4. Yep! you were right. My missing bracket in my example here wasn't the problem, but you were right about the condition never evaluating to true the way my statement was outside the loop. I moved the condition inside the loop. Great. Thank you.
  5. Thank you. However I caught your point just as you were sending it. It is not like that in the actual code. The if condition is outside the loop. I accidentally omitted a right curly brace in the code I posted (sorry). The problem still exists.
  6. I must have deleted a right curly brace (}) from the code when I pasted it here because I don't see it in the code. It is in the actual code. It would not have produced any output if it wre missing. Here's a snipped of the code with the curly brace still where it actually still is: // ... if (isset($_POST['guess'])){ $_SESSION['guess']=$_POST['guess']; } // missing curly brace is still there. It accidentally got deleted from my example. if (isset($_POST['qid'])){ $_SESSION['qid']=$_POST['qid']; print_r($_SESSION); // ... Sorry for the omission. That was NOT the error I was writing about, but it WAS an error to fail to include it in the code I posted.
  7. I am temporarily including some extra "testing" code within my program to help me troubleshoot it. It won't be in the final program. I'm trying to compare the correct answer in a quiz program ($ans) with the user's answer ($_POST['guess']). Even when the user picks the right answer, the program still spits out, "wrong!" I am not seeing my logical error here, but I obviously have one. I attached a screen shot of the output. I hope it helps. Thank you all. if (isset($_POST['qid'])){ //qid is the question id $_SESSION['qid']=$_POST['qid']; print_r($_SESSION); $ans = $db->query("SELECT answer FROM QuestionsAnswers WHERE questionid = " . $_SESSION['qid']); echo "<br />"; print_r ($ans); //correct answer while($row = $ans->fetch(PDO::FETCH_ASSOC)) { echo "<p>Here is my Thursday 6pm attempt:xxx" . intval($row['answer']) . "xxx</p>"; echo "<p>User guessed:xxx" . intval($_POST['guess']) . "xxx</p>"; echo '<p>the extra exes ("xxx") are to demonstrate there are no spaces in the field data.</p>'; } if (intval($row['answer']) == intval($_POST['guess'])){ //values converted to integers just in case one or both is/are a string echo "<p>Right!</p>";} else{ echo "<p>wrong!</p>"; } It is bugging me that PHPFreaks won't let me log into my regular account. Cool. At least I can log in using Facebook. Different account, same person. It is still me. Thanks to all for any help with this one. (please see attached output.)
  8. print $_SESSION['question_ids'][$_SESSION['question_pointer']]; // line 61 did the trick. Thanks to PravinS and ignace
  9. In my quiz program, I'm getting the following error: I have two session variables: question_ids is an array, and question_pointer is an integer that is supposed to tell the program which question_ids to display. After each question, the question_pointer will get incremented and the next question will be displayed. I get confused with all the single quotes (apostrophes) and double quotes (quotation marks.) Here is the problematic line 61: <?php // ... (other code ) ... print $_SESSION["question_ids[$_SESSION['question_pointer']"]; // line 61 // ... (other code ) ... ?> Since learning about session variables and especially arrays as session variables, I have had a problem visualizing how to write the code to place the session variable as the array element for another session variable. How could I do this that would work? Thanks.
  10. Hello PHP freaks. I'm bummed out because I only wanted to log in and post my PHP question, but I am away from my home computer and my passwords aren't saved on my laptop. So I signed in using Facebook and I had to start a new account. I hope I will be able to merge this new account with my regular account once I get home. Okay, I'm off to the help forum to post my question.
×
×
  • 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.