Jump to content

digital_priest

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

digital_priest's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Oh, yea! Don't know why I didn't think of that. I was using the same function for all of the variables, some of which are names of employees with roles, but some are names of locations or contacts, etc. A second function was finding the ID codes for the roles. That should have jumped out at me. So I've added a third argument to the function, $role, and use it to create a joined table when it has an appropriate value. Works like a charm! Thanks! (still don't know why that didn't work, though, which bugs me, but I've got other things to do than worry over code I'm not using....)
  2. And I'm doing this: $info['role'] = $instructor_code; to add the key=>value to the array represented by $info in: foreach($other_instructors_test AS $instructor => $info) Adding the role code to the $other_instructors_test array is the real goal, all the printing is just attempts to debug
  3. echo '<pre>'; print_r($other_instructors_test); echo '</pre>'; Array ( [Amos] => Array ( [new] => 1 [id] => 196 ) [Diahnne] => Array ( [new] => 1 [id] => 197 ) )
  4. $instructor_code comes from a function that finds ID codes from a table of role names (head instructor, instructor, volunteer, etc.). The function call actually appears in the previous line of code. $instructor_code = get_role_code('instructor'); echo("OTHER_INSTRUCTORS_TEST IS... <br />"); print_r($other_instructors_test); foreach ($other_instructors_test AS $instructor => $info) { echo("<p>INSTRUCTOR: "); print_r($instructor); echo("<br />INFO: "); print_r($info); echo("<br />ROLE CODE: "); print_r($instructor_code); $info['role'] = $instructor_code; echo("<br />INFO IS NOW: "); print_r($info); } echo("<p>OTHER_INSTRUCTORS_TEST (POST ROLE CODES): <br />"); print_r($other_instructors_test);
  5. I'm feeling very thick because I should know why this isn't working, but I've been staring at this for too long—so I'm looking for help. I'm trying to add a key/value to the second set of arrays in a 2D array. It looks like it works within the foreach loop, but then doesn't show up later. Here's the PHP code: echo("OTHER_INSTRUCTORS_TEST IS... <br />"); print_r($other_instructors_test); foreach ($other_instructors_test AS $instructor => $info) { echo("<p>INSTRUCTOR: "); print_r($instructor); echo("<br />INFO: "); print_r($info); echo("<br />ROLE CODE: "); print_r($instructor_code); $info['role'] = $instructor_code; echo("<br />INFO IS NOW: "); print_r($info); } echo("<p>OTHER_INSTRUCTORS_TEST (POST ROLE CODES): <br />"); print_r($other_instructors_test); And here's the results: Why isn't the ['role'] value showing up in the $other_instructors_test array? Thanks for your help, Amos
  6. I'm trying to get the average and the standard deviation of several different selections of entries over several date ranges. The code below is what I've come up with, but I'm getting an error that AVE is not a function for my database. Am I using AVE wrong? Thanks for your help! $day = array(30, 60, 90, date('z')); $weight_stats = array(); foreach ($day as $days) { $ave_vol_sql = "SELECT AVE(weight) as ave_weight, STDDEV_POP(weight) as dev_weight FROM metrics_weight_height_bmi WHERE date_measured BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE()"; $ave_vol_results = mysql_query($ave_vol_sql) or die(mysql_error()); $ave_vol = mysql_fetch_assoc($ave_vol_results); $weight_stats[$days] = array(ave => $ave_vol['ave_weight'], vol => $ave_vol['dev_weight']); }
  7. THAT'S IT!! It turns out the EVERY field in the whole darn form was named "weight" except the one named "goal_weight", which were the only two I was using for testing. Fixing other people's code is harder than writing your own. Thanks!
  8. I'm going batty trying to find two problems in this small bit of code. I'm hoping that someone will point out the typo or whatever at best, or at worse tell me that the error is somewhere else (though I have no idea where else it could be). One problem is that one of the values in a form is not being posted: in the code/results below, you can see that the variable $_POST['weight'] corresponding to the form field named "weight" is set in the $_POST array, but there's nothing being echoed—even when there is something entered into the weight field in the form. The other problem is the syntax error MySQL v5.0 is returning on the INSERT statement. It's such a simple statement that I can't believe this is the real problem. Typo? Reserved word? (Also, this is not my own code, I'm helping someone learn PHP/MySQL, and I'm dreading the idea that there is something wrong with some distant part of the spaghetti). Thanks for looking over the code below and I appreciate whatever thoughts you can offer. This is the code for the form—with nonessential stuff removed: <form name="member_metrics_weight_add" method="post" action="member_metrics_weight.php"> <table width="500" align="center"> ... <tr> <td colspan="2">Weight</td> <td width="538">Goal Weight </td> </tr> <tr> <td height="35" colspan="2" valign="top"><input type="text" name="weight" class="form_fields" id="weight" value="<?PHP echo $weight;?>" size="30" maxlength="30"> </td> <td height="35" colspan="2" valign="top"><input type="text" name="goal_weight" class="form_fields" id="goal_weight" value="<?php echo $goal_weight;?>" size="30" maxlength="30"> </tr> And here is the PHP code that processes that part of the form: //member_id is already retrieved from session variables if (isset($_POST['submit'])) { //the following is just trying to find the error, why the $_POST['weight'] is set, but empty, even though the field was filled out if (isset($_POST['weight'])) { echo("<p>weight is set</p><p>weight: ".$_POST['weight']."</p>"); } else { echo("<p>weight is NOT set</p>"); } //real code starts here $weight = $_POST['weight']; $goal_weight = $_POST['goal_weight']; $e_sql=" INSERT INTO members_metrics(member_id,weight,goal_weight) VALUES($member_id,$weight,$goal_weight)"; echo("<p>".$e_sql."</p>"); //more bug seeking code $e_results = mysql_query($e_sql) or die(mysql_errno()." ".mysql_error()); } And the output from the PHP code is the following: weight is set weight: INSERT INTO members_metrics(member_id, weight, goal_weight) VALUES (383, , 456) 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 456)' at line 2 And, just to be sure, here's the relevant bits of the members_metrics table: id int(11) No auto_increment member_id varchar(255) utf8_general_ci No weight varchar(255) utf8_general_ci Yes NULL goal_weight varchar(255) utf8_general_ci Yes NULL
×
×
  • 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.