Jump to content

ThisisForReal

Members
  • Posts

    34
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

ThisisForReal's Achievements

Member

Member (2/5)

0

Reputation

  1. foreach ($_SESSION['threshold'] as $k => $v ) { if ($v > $_SESSION['compare']) { break; } $output = $k; } echo $output; That's the elegant solution I was looking for. Thanks so much! I really appreciate it.
  2. I've never taken a logic class, or a CS class. This is likely very easy to anyone with any background in either topic. I have an array, $_SESSION['thresholds'], where I've given the array keys values such as "thresholdA", "thresholdB", "thresholdC", "thresholdD", etc. with corresponding elements that increase in value (5,15,50,75,etc.). They array is currently mapped in ascending order. I have a variable, $_SESSION['compare'], that I want to compare against all the elements in the $_SESSION['thresholds'] and, ultimately, I want to be able to echo/print the key of the largest array element that is less than the value of $_SESSION['compare']. Using the above values, if $_SESSION['compare'] == 21, then I would love to echo/print "thresholdB". What's the best method to accomplish this? Array_Walk? A switch statement? I first tried while() and was trying to use the pointer in the array, but I found that if I used next() to see if the next array element was larger, the actual use of next() within the while() statement caused the pointer to advance anyways. That seemed like the wrong path to take. The switch statement I've tried is failing, and I don't know how to use a comparison within an array_walk when I want to break out once the largest value is determined. This seems like such a basic function of array and variables but I'm struggling with this. Any advice would be much appreciated. Here's some of my tests that failed: reset($_SESSION['thresholds']); while( (current($_SESSION['compare']) < $_SESSION['thresholds']) and (key($_SESSION['thresholds']) <> 'thresholdMAX')) next($_SESSION['compare']); That final next() statement advances me one step too far. Should I use this and then backup one step? That might create problems of its own. Next I tried switch: switch ($_SESSION['compare']) { case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdMAX']): $output = key($_SESSION['thresholds']['thresholdMAX']); break; case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdD']): $output = key($_SESSION['thresholds']['thresholdD']); break; But that wasn't working and seems like the wrong way to go about this. Can anyone point me in the right direction? Thanks so much in advance!
  3. I'm fairly new to using AJAX and JQUERY to call back to the server, process a form's contents, and then update a div file accordingly. This new project has almost everything in a single div (id="mainContent"). This is the <div> that I will be updating through the ajax call. My div has a lot of different hyperlinks at the moment (text, image, and form submit button). I know how to do an update for a page that has a single form with a single submit button. In order to turn my site into an ajax driven site, should I take all these image links and wrap individual forms around them? What about the text links? It all seems very cumbersome and I'm curious how you experts would tackle the issue. Any assistance on best practices would be greatly appreciated! Thanks in advance.
  4. Excellent - I found the output buffering option on my WampServer and turned that off. Now I'm getting similar behavior in both production and development. Thank you for that tip. With regard to the error, I'm not getting any warning/failure text from php. (Caveat: I haven't yet adhered to the header() sticky at the top of this forum about logic placement) I'm just seeing my gif background, the header, and then an empty div box that holds the usual content. I'm guessing that's still a standard header error issue. I am still perplexed why my site worked great for months on end and all of a sudden it is giving me fits now. It would never be a browser issue, right - the problem rests on the server side? Thanks again for such awesome community feedback. For us self-taught folks, it's wonderful.
  5. I have a web site with a user login requirement that has worked splendidly for months. I also have a development version of my site on my laptop, localhost. At the moment, I have identical code on both the development and production sites. I'm getting some header error in production, but not on development. Is it guaranteed that my page is generating some white space, or is it possible that there may be another issue at hand (I'm fairly non-technical, so I'm grasping here - my web host upgraded to a different PHP version that is creating whitespace in production while development on my laptop is a different version of php, my web host has done something else that is causing this, fill in the blank with your own conspiracy theory)? Any reading material out there (besides the php.net manual) that explores what may be going on? Thanks in advance - this community has been wonderfully helpful for me over the last year!
  6. Does this method work if my form is NEVER going to get submitted (I won't even have a submit button). I'm going to use serialize to collect and arrange the form data, and send it off to my php file that will process and then update the divs on the user's page. The user would then modify their selection and press the button again. My understanding is that if I was using an input submit button, I would need a catch to prevent the submit from fetching the action="" page. Whereas, by using a button, I wouldn't have to worry about catching any action.
  7. This is my first attempt at ajax using jquery. I've successfully done ajax without jquery borrowing someone else's tutorial where I used onkeyup="showHint(this.value)" to provide search hints for my online movie database, but I want to learn jquery yet am struggling. I'm inept with OOP, and I have zero javascript experience (aside from using scripts from others that have been made publicly available). Background: I'm attempting to use the jquery serialize() function to take the contents of a form, send it over to a php file through the use of a button, <button type="button">, "submit_test.php" (preferably via post), where I'll do all my crazy php processing. When submit_test.php is finished, I'll have strings (in html format, I guess, with "<p>" and "<br />" mixed in) which I'll use to update 2 divs on my original page. This is what has been tripping me up. I've been able to demonstrate that I'm serializing the data into a format that I want via this jquery script (which displays the string): <script> function showValues() { var str = $("form").serialize(); $("#results").text(str); } $(":checkbox, :radio").click(showValues); $("select").change(showValues); showValues(); </script> I just need help passing that along to submit_test.php My questions are basically syntax: <script type="text/javascript" language="javascript"> $( '.button' ).click(function() { function(){ var data = $(this).serialize(); $.post( "submit_test.php", { action: "ajax_verify_form", data: data }, function(response){ $('#div_1').html($('#inner_1' , resp).html()); alert(response); return false; } ); return false; } ); </script> var data = $(this).serialize(); <-- I doubt I'm doing this right. data: data <-- this is probably troublesome, too. Can someone explain what would typically go in the var data = ..., and how that relates to the data: piece of the script? I feel like I'm so close, but every tutorial I've googled thus far is doing something different than what I'm trying to accomplish and I just haven't been able to put it together yet. To see the page, I've got it stripped down to just the part at hand here: http://www.cv-industries.com/ajax_test Thanks so much in advance for any assistance you can provide!
  8. Look at that! Didn't know there was a substr_count() function. Much thanks.
  9. I'm not a programmer, so sometimes the php.net/manual reads like a foreign language to me. I have a quick interpretation question: I'm generating data in PHP for a MySQL stored procedure that has two comma separated value inputs. The second input is always a series of 0's and 1's. I'm trying to count the number of 1's for the second input (in the example below, it would be "3"). Example input sent to MySQL: $query_resolve = "CALL spParticipant_Test ('188,216,342,81,117,56','0,1,1,0,0,1')"; http://www.php.net/manual/en/function.count-chars.php is mostly helpful, but I am hoping for clarification on the mode I want to run. Do I want to run mode "1"? Thanks so much for any feedback!
  10. I found the answer - use chr(13) and chr (10). See code here: $chr = chr(13) . chr(10); $members_string = implode($chr,$list_of_members); Thanks to Maven1 at php.net.
  11. $members_string = implode('\n\n',$list_of_members); //I'm trying to put the carriage new line here Ignore that earlier alternate array name. I try to change names before posting to this forum so that things are easier for you all to follow. Missed that one.
  12. No luck on a variety of attempts to populate the string with various forms of \n, inside double quotes, single quotes, with \r, without it. So I'll back up a moment and show the bigger picture and see if someone knows a better solution to my dilemma. Objective: Send an email using php's mail() to a group leader that will show all the members of the group. Since I'm sending a bit more information than just the name of each member, formatting the email is KEY. My Approach: The easiest way to format the letter to be legible is to insert a carriage return or new line after each member. To do that I tried the following: list_of_members = array(); foreach($member_first as $key => $value) $list_of_members[$key] = $value . ' ' . $member_last[$key] . ' | ' . $class[$key] . ' | ' . $join[$key]; $members_string = implode('\n\n',$part_line); //I'm trying to put the carriage new line here Now I have one string that contains all the members with the '\n\n' between each member. When inserting this into the body of the email, I thought the contents would create new lines in the email. // Send Email $to = "$email"; $subject = "Members of your group"; $message = "Hello $admin,\n\nThis is the list of members to your group:\n$members_string" . "\n\nRegards,\r\n Team Leader Alpha\n\n"; $headers = 'From: noreply@mysite.net' . "\r\n" . 'Reply-To: noreply@mysite.net' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers) or die("Email was not sent"); The reality is that while all other carriage returns work, the email shows the member string verbatim without following the direction of the new line command (example follows:): What other method could I use to get the formatting in the email to allow for a carriage return between each member? Thanks!
  13. So if when concatenating the $string, if I build it with double quotes that will work? I'll give it a try.
  14. I'm working on a project where I have concatenated a string that lists all of the members of a group and want to email them to the group administrator. An example string may look like this: $string = 'Mark Ruiz | class A | January 7, 2010\n\nJason Adams | class B | January 9, 2010.\n\nDan Hernandez | class A | March 4, 2010.'; When I put that into the message of my email: $body = "Hello $admin,\n\nThis is the list of members to your group:\n$string." The \n\n that separates each member in the string is still considered part of the string, so the email doesn't recognize that it should start a new line. Does anybody know a good work around to this problem? Thanks so much!
  15. I think that's what I'm looking for. 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.