Jump to content

ppgpilot

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ppgpilot's Achievements

Member

Member (2/5)

0

Reputation

  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
  8. A puzzle. Hope you have the answer... I am trying to call data from a db and then input the data into another db the data is for a diet website the user chooses a recipe. the recipe has several rows with several fields i.e. item1, calorie, fat, protein item2, calorie, fat, protein item3, calorie, fat, protein etc. I need to pull the entries from the “recipe” db and place them into the “history” db containing the same field names. I know I need a loop, but have not found the proper way to solve the problem My latest attempt is included below. I can echo the data correctly, but only the first entry enters the db Any assist would be appreciated. <?php $sql=("select * from $tbl5 where recipe_name = '$recipe_name' "); $result = mysql_query($sql); $works = mysql_num_rows($result); require 'my_error.php'; while($rows = mysql_fetch_array($result)) { $item = $rows['item']; $amount = $rows['amt']; $calorie = $rows['calorie']; $fat = $rows['fat']; $fat_calories = $rows['fat_calories']; $carb = $rows['carb']; $protein = $rows['protein']; $sugar = $rows['sugar']; // insert this data into the history ref the date entered on the initial page $sql = ("insert into $tbl3 ( user_name, entry, day, item, amt, calorie, fat, fat_calories, carb, protein, sugar ) values ( '$user_name', '$entry', '$day', '$item', '$amount', '$calorie', '$fat', '$fat_calories', '$carb', '$protein', '$sugar' ) "); $result = mysql_query($sql); $works = mysql_affected_rows(); require 'my_error.php'; // end while } ?>
  9. I have renewed my computer after some problems with the hard drive – The problem – after reloading the computer with PHP 5 -- I cannot get html forms to upload images to a folder – in any of my php-based programs. It used to work… before the computer renewal I have the same version of PHP as before and the same php.ini file. Any idea what could be preventing the $_FILES from working in files that used to work great? CHMOD is 777 and I have the right form enctype... I suspect something in the php.ini, but just a feeing… Any thoughts???
  10. Ok... Which of the latest 5.2.4 would be the most appropriate for a windows Vista machine Complete Source Code PHP 5.2.4 (tar.bz2) [7,430Kb] - 30 August 2007 md5: 55c97a671fdabf462cc7a82971a656d2 PHP 5.2.4 (tar.gz) [9,478Kb] - 30 August 2007 md5: 0826e231c3148b29fd039d7a8c893ad3 Windows Binaries PHP 5.2.4 zip package [9,702Kb] - 30 August 2007 md5: 979b8a305b028b296b97ed72322026b2 PHP 5.2.4 installer [22,002Kb] - 30 August 2007 md5: ad23dcc391a8c26c7d387eb5e9bf1ffb PECL 5.2.4 Win32 binaries [4,363Kb] - 30 August 2007 md5: dd98dfe607ceb98e727c394d5bd679fb PHP 5.2.4 Non-thread-safe Win32 binaries [9,608Kb] - 30 August 2007 md5: 7728b869cfe3b8b7f1751da0a298fc12 PECL 5.2.4 Non-thread-safe Win32 binaries [4,110Kb] - 30 August 2007 md5: 44302972cffd2b9cf05cb7131b56056a
  11. I am setting up a new computer and had a version of PHP on my old system and need ot upgrade. The program options at PHP.com does not seem to intuitive to a newbie. I am working on a windows box using Vista Any help would be appreciated
  12. I have a script that uploads a jpg from a form. PHP handles the form The image is stored in a folder and I have permissions the script works great on my old computer (xp-pro) and on the apache server the script does not work in new computer / new PHP install / Vista OS This is what displays from the local server / vista / IIS7 debugging info:Array ( [img1] => Array ( [name] => Desert Landscape.jpg [type] => [tmp_name] => [error] => 6 => 0 ) ) This is the correct display from the Apache server debugging info: Array ( [img1] => Array ( [name] => Autumn Leaves.jpg [type] => image/pjpeg [tmp_name] => /tmp/php6nXuLM [error] => 0 => 276216 ) ) I am missing file tmp name, file size, file type --- only the name is in the array. also the script throws an error 6 - tmp folder not found I have tried various folders and the permissions is set to read write. the php.ini -- ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). upload_tmp_dir = c:\tmp\ ; Maximum allowed size for uploaded files. upload_max_filesize = 20M Any idea what the problem might be? I have checked the php.ini and it seems all the options needed are available and unremarked The I have the mbstring before the efix in the PHP.ini file been at this for 5 days and any help would be appreciated!!! David
  13. I ran across a problem that I have not been able to solve when submitting a form to be handled by the same page. I am using $_SERVER[‘PHP_SELF’] On local Windows XP pro it works fine On my server - Linix / vieving with IE-7 / Fire Fox it does not work I have been using $_SERVER[‘PHP_SELF’] to handle files for well over a year with 100% success. The problem is this: usually the $_SERVER[‘PHP_SELF’] provides the file address: i.e. support_files/comment.php and not the host address "mysite.com. Clicking submit has always prepended the Host – i.e mysite.com/ --- and it all worked well as the display url was --- mysite.com/support_files/comment.php Recently, for some reason I cannot discover, when I click submit, I only get the $_SERVER[‘PHP_SELF’] (file name) and not the host info. and this fails. No problems on XP pro on my local server And this only happens in one set of folders and subfolders on the server and all files and folders are affected in that set – Other folders apart from this one set seem unaffected and the $_SERVER[‘PHP_SELF’] works fine. While trying to track the problem down I find the following removing the $_SERVER[‘PHP_SELF’] in IE7 will cause a default and it will work : mysite.com/ support_files/comment.php placing any character in front of $_SERVER[‘PHP_SELF’] will once again prepend the host, but also other address information and fails i.e. placing a “-” in front -$_SERVER[‘PHP_SELF’] makes the following http://mysite.com/support_files-//support_files/comment.php so I am replacing the $_SERVER… with the absoulte URL and everything works. What might be wrong in this situation? I prefer to use the $_SERVER Global I did introduce a .htaccess file about the same time to turn off the auto.session_start – but changing the settings or removing .htaccess completly does not seem to have an affect. Perhps you have come upon this before. Puzzled! David
  14. Does anyone have a script that will adequtely validate a user JPG entry to prevent hacks? David
  15. I have a problem and cannot find the answer... I am receiving an error - "Array to string conversion" on the page head I have the following which is throwing the error: [code=php:0] $_POST = array_map('stripslashes', $_POST); [/code] I am using a form multiple select box to select emails into an array: [code=php:0] <select multiple name="client_email[]" size="3" > EOT; $sql = ("select client_name, email from $tbl1"); $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) {     $client_name = $row['client_name'];     $email = $row['email'];     echo "<option value=\"$email\">$client_name</option>"; } [/code] then run the array through a php mail(): [code=php:0] if(isset($_POST['client_email'])) { if(is_array($_POST['client_email'])) {         $client_email = $_POST['client_email'];         foreach ($client_email as $email)         {             mail(             $email,             $subject,             $client_message,             $header             );         } }elseif(!is_array($_POST['client_email'])) {         $email = $_POST['client_email'];             mail(             $email,             $subject,             $client_message,             $header             ); } } [/code] Then the error "Array to string conversion" If you have the answer and a fix, please let me know Thanks 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.