Jump to content

ppgpilot

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by ppgpilot

  1. Thanks for the reply. I should mention I am very new to loops… I will have an array from the SELECT and I am using a WHILE statement to run through the array. So far so good $sql=("select * from $tbl3 where day = '$org_date_unix' order by item"); $result = mysql_query($sql); require 'my_error.php'; $works_call = mysql_num_rows($result); while($rows = mysql_fetch_array($result)) { $item = $rows['item']; etc…} I then display these on the page and all is well. But placing them back in is where I am having the problem. Once I define the variables - maybe they need to be arrays since there will be an numberof them - I need to loop them back into the database with the newly defined date variable to create the same number of records with 10 fields each. Yes? Would another WHILE statement be best, a FOREACH or a FOR loop be the best to use? - and I will begin my research from there. Would I INSERT within the original WHILE statement that selected the records? Or outside in a different loop. Can’t quite get my head around this yet. Knowing the concept and best approach / type of loop for this operation will save me a bunch of time. Thanks!
  2. I have a DB with 10 fields Records are entered under a date There can be 1 to 30 records for a given date I need to copy all records of a given date with the 10 fields of each... Into the same DB only changing the original date to a new date Sounds easy, but so far I haven't been able to make it work. Any nudge in the right directiion would be much appreciated.
  3. I am writing a script, but keep getting a 500 error page. I've tried various tricks to isolate the problem to no avail. My old system would always send me an email to report the error, but since my new box, it isn't working The major change from my old setup is that I am now using fast CGI I rememeber that there is a log that records errors but I havn't been able to find it if there is one... Or I am looking in the wrong places. Can anyone nudge me in the right direction on this? Thanks, David
  4. I am trying to find a way to copy a number of records from db 3 back into db 3, only changing the date of the copied records I have a PHP script that I use to record calories. I do this by entering items eaten during the day. I enter a food item from a dropdown menu. These items are in db 4 and each has the calorie count, protein, fat etc. for that item The script places the item and data from tbl 4 into tbl 3 So I enter maybe 15 items for each day, all unique except the $day variable which is the same in all the entries (say 15 records) since all items belong to that day I find it convienient now to copy a days worth of entries (15 entries in this example) from tbl 3 back into tbl 3, except change the $day variable from yesterday to today This is so that I do not need to enter the same items again for multiple days - boring, tedious, waste of time, etc. So if I plan to eat the same items today as I did on a past day, The script asks for the original day, then the new day so far so good It then needs to copy the original days entries back into the db, only changing the date field from the old date to the new date for each of the entries I am sure this is simple, I just don't have enough experience to know how to make it happen. Someone on the sight showed me how to copy 1 record, but I need to copy multiples. So, I carry in the $original_date and the $new_date the fields for tbl 3 are as follows: day, type, history period, item, amt, calorie, fat, fat_calories, protein, carb, sugar, sodium Anyone have an answer for this one? Thanks!! David
  5. I used to code a long time ago - PHP5. It is slowly coming back to me but not fast enough... I need to copy data from a mysql data base and put it back in unchanged with another date reference. This is a calorie recorder that tracks daily calories - food type, calories, protein, carbs, etc. I simply want to take each entry in that day, then copy it exactly except changing the date recerence. If I could say "copy all entires where date = (date) into DB with new date (date), that would do it. The only thing I can think to do is pull each item out and place it back into the DB with a while statement. There has to be an easier way... If that is my only option, I need to figure out how to create a while statement to handle an array to do the job. Any thoughts? Thanks for the help!! David
  6. Thank you andrewgauger - that solved the problem and I am up and running! I knew it was something simple. I need to ask for help sooner! Thank you litebearer - you are right, there are other products in the formula that together add up to 100%, but only tracking the fat, carb, and protein in this program. David
  7. I've been coding PHP for 5 years and have not run into this problem. After 3 days it is time to ask for help. My script looks at two numbers and returns a % of the two. The first number is total calories and the second is protein calories. The object is to find the % of protein calories compared to total calories. (same with Fat and Carbs also) Protein calories / total calories should return a fraction which is the protein % of the Total Calories (i.e. 200 protein calories / 800 total calories = 25%) This works using $variables as long as the total calories is less than 1,000. Above 1,000, it does not work, but returns a number that doesn’t make sense. HOWEVER, it DOES work using the actual numbers and not $variables even though the $variables test good and contain the right amount. $protein_count1 = ($protein*4) / $total_caloriee; $protein_count2 = $protein_count1 * 100; $protein_count = number_format($protein_count2); Result for under 1,000 calories is correct Total Running Calories 428.00 Fat = 11 % Protein = 29 % Carbs = 54 % Result Over 1000 calories is incorrect Total Running Calories 2,881.31 Fat = 48,077 % Protein = 43,332 % Carbs = 53,364 % Correct numbers should be Fat = 33 % Protein = 30 % Carbs = 37 % These are the values that display when using the actual number and not feeding the number through a variable. ///////// ALSO!!!! Trying to filter the total calories with an IF statement isn’t working either !!! IF($total_calories >= 1000) even if the number is above 1,000, it returns false. if($total_calories > 1000) { echo "greater than $total_calories <br /><br />"; }else{ echo "less than $total_calories <br /><br />"; } Result is always “less than” whether < or > 1,000 - while showing the appropriate number of total calories . I have tried changing the variable names with the same results. This is very simple stuff and should work, but it isn’t. Any idea what is happening. Thanks for any help... David
×
×
  • 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.