[PHP-DB] Re: [PHP] goto - My comments
On Sat, Dec 18, 2010 at 11:44 PM, Robert Cummings wrote: > On 10-12-19 12:17 AM, Ethan Rosenberg wrote: >> >> Dear List - >> >> Thanks to all for your EXCELLENT comments. I definitly agree that >> goto is a command to be avoided at all costs. > > Closed-minded drivel (or you're buttering up the popular opinion crowd). A > better approach is that goto should be used with caution. > > As for doing your homework for you... ummm no thanks. You should take the > time to do the exercise so you gain the benefit of experience. I would have thought school would have been out on account of Christmas and all. In any event, here's my rewrite: switch (true) { case isset($_POST['Site']) && trim($_POST['Site']) != '': $sql1 = $sql1 . "site = '$ste'"; break; case isset($_POST['MedRec'])&& trim($_POST['MedRe']) != '': $sql1 = $sql1 . "MedRec = '$req'"; break; // ... default: if(isset($_Request['Sex'])&& trim($_POST['Sex']) != '' ) { if ($_REQUEST["Sex"] == "0") $sex = 'Male'; else $sex = 'Female'; $sql1 = $sql1 . " = '$sex'"; $sexdone = 1; } if(isset($_POST['Hx'])&& trim($_POST['Hx']) != '') { $sql1 = $sql1 . "Hx = '$hx'"; $done = 1; } } You could also do an if / else if / else if / ... / else. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] goto - My comments
On 10-12-19 12:17 AM, Ethan Rosenberg wrote: Dear List - Thanks to all for your EXCELLENT comments. I definitly agree that goto is a command to be avoided at all costs. Closed-minded drivel (or you're buttering up the popular opinion crowd). A better approach is that goto should be used with caution. As for doing your homework for you... ummm no thanks. You should take the time to do the exercise so you gain the benefit of experience. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] goto - My comments
Dear List - Thanks to all for your EXCELLENT comments. I definitly agree that goto is a command to be avoided at all costs. In this case, I could not figure out how to acheive the desired result without the goto. So being a newbie, I humbly request that you show [and at the same time teach] me how to rewrite the code to eleiminate the goto. Additionally, would you please do the same for the code I list below. This code runs perfectly. == This is the form: Data Search Data Search Site: Record Number: First Name: Last Name: Phone: Height: Male Female *** This is the program - Search of Data "); //printf($sql1); $result = mysqli_query($cxn, $sql1); if(($num = mysqli_num_rows($result)) == 0) die ("No Records Retrieved"); ?> Search Results cellspacing="55" rules="all" frame="box"> Site Medical Record First Name Last Name Phone Height Sex History // printf("To exit, click the EXIT button below./>"); // printf("%s\t%s\t%s\t%s\t%s","Site","Record", "Weight", "Height", "BMI"); while($row = mysqli_fetch_array($result)) { echo "\n"; echo " $row[0] \n"; echo " $row[1] \n"; echo " $row[3] \n"; echo " $row[4] \n"; echo " $row[2] \n"; echo " $row[5] \n"; echo " $row[6] \n"; echo " $row[7] \n"; echo "\n"; /* $site2 = $row[0]; $record2 = $row[1]; $bmi2 = $row[2]; $wgt2 = $row[3]; $hgt2 = $row[4]; printf("%s\t%d\t%d\t%d\t%3.1f", $site2, $record2, $wgt2, $hgt2, $bmi2);*/ } /*printf("%s\t%s\t%s\t%s\t%s","Site","Record", "BMI", "Weight", "Height"); printf(""); while( $row = mysqli_fetch_array($result)) { $site2 = $row[0]; $record2 = $row[1]; $bmi2 = $row[2]; $wgt2 = $row[3]; $hgt2 = $row[4]; printf("%s\t%d\t%3.1f\t%d\t%d", $site2, $record2, $bmi2, $wgt2, $hgt2); }*/ mysqli_free_result($result); mysqli_close($cxn); ?> == THANK YOU EVER SO MUCH FOR YOUR HELP. Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] Problems w/ goto
check out my new sig. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] Problems w/ goto
or maybe it's saturday morning and i'm drunk? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] Problems w/ goto
You approved all of us, no matter the peer review, when you signed up or the list. The accumulation of knowledge, is insurmountable when delivered as a whole, but devourable if you need satiation of appetite. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP] Problems w/ goto
On Sat, Dec 18, 2010 at 12:45 PM, Geoffrey Bernardo Van Wyk wrote: > Ethan, > > I tried to test your code, but I get this error next to the labels and goto > statements: As a 'professional' programmer, working for an entity, we deal with these problems as we go. As novices, we deal with it on a daily basis. As computer scientists, we think of it as a problem already solved, but in need of translation. Understand, buddy pal. > > Language feature not compatible with PHP version indicated in project > settings > > I have PHP 5.3.0. > > Geoffrey > > _ > > From: Ethan Rosenberg [mailto:eth...@earthlink.net] > Sent: 17 December 2010 06:39 PM > To: php-db-lists.php.net; php-gene...@lists.php.net > Subject: [PHP] Problems w/ goto > > > > Dear List - > > I am sending this again since it does not seem to have posted. > > Ethan > +++ > Dear List - > > Thank you with your excellent help in the past. Here is another puzzler > > > I am trying to write a program that can have two(2) independent forms > in one PHP file. When I run the code below [from PHP - A Beginner's > Guide], to which I have added a second form, it freezes. Without the > goto statements, it runs. When it does run, it displays both forms > on one Web screen. What I desire is for the first form to be > displayed, the data entered and then the second form displayed. In > an actual, not test program like this one, the data in the second > form would be dependent on the first form. > > What did I do wrong? > > Thanks in advance. > > Here is the code: > > > "DTD/xhtml1-transitional.dtd"> > http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> > > Project 4-4: Age Calculator > > > Project 4-4: Age Calculator > // if form not yet submitted > // display form > > $ender = 0; > begin: > > if($ender == 1) > exit(); > if (!isset($_POST['dob'])) > { > start1: > > echo " "; > echo " Enter your date of birth, in mm/dd/ format: "; > echo " "; > echo " "; > echo " "; > echo " "; > > goto begin; > // if form submitted > // process form input > } > else > { > starter: > if (isset($_POST['cat'])) > goto purr; > // split date value into components > $dateArr = explode('/', $_POST['dob']); > > // calculate timestamp corresponding to date value > $dateTs = strtotime($_POST['dob']); > > // calculate timestamp corresponding to 'today' > $now = strtotime('today'); > > // check that the value entered is in the correct format > if (sizeof($dateArr) != 3) { > die('ERROR: Please enter a valid date of birth'); > } > > // check that the value entered is a valid date > if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { > die('ERROR: Please enter a valid date of birth'); > } > > // check that the date entered is earlier than 'today' > if ($dateTs >= $now) { > die('ERROR: Please enter a date of birth earlier than today'); > } > > // calculate difference between date of birth and today in days > // convert to years > // convert remaining days to months > // print output > $ageDays = floor(($now - $dateTs) / 86400); > $ageYears = floor($ageDays / 365); > $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); > echo "You are approximately $ageYears years and $ageMonths months > old."; > goto meow; > } > > meow: > if (!isset($_POST['dob'])) > goto begin; > if (!isset($_POST['cat'])) > { > > > echo " "; > echo " Enter your kitten's name: "; > echo " "; > echo " "; > echo " Kitten\" />"; > echo " "; > > } > else > { > purr: > $name_cat = $_POST['cat']; > > echo "Your Kitten is $name_cat"; > $ender = 1; > } > if ($ender == 0) > goto begin; > first_step: > ?> > > > > > > > Ethan > > MySQL 5.1 PHP 5 Linux [Debian (sid)] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > _ > > No virus found in this message. > Checked by AVG - www.avg.com > Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10 > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] RE: [PHP] Problems w/ goto
Ethan, I tried to test your code, but I get this error next to the labels and goto statements: Language feature not compatible with PHP version indicated in project settings I have PHP 5.3.0. Geoffrey _ From: Ethan Rosenberg [mailto:eth...@earthlink.net] Sent: 17 December 2010 06:39 PM To: php-db-lists.php.net; php-gene...@lists.php.net Subject: [PHP] Problems w/ goto Dear List - I am sending this again since it does not seem to have posted. Ethan +++ Dear List - Thank you with your excellent help in the past. Here is another puzzler I am trying to write a program that can have two(2) independent forms in one PHP file. When I run the code below [from PHP - A Beginner's Guide], to which I have added a second form, it freezes. Without the goto statements, it runs. When it does run, it displays both forms on one Web screen. What I desire is for the first form to be displayed, the data entered and then the second form displayed. In an actual, not test program like this one, the data in the second form would be dependent on the first form. What did I do wrong? Thanks in advance. Here is the code: http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> Project 4-4: Age Calculator Project 4-4: Age Calculator "; echo " Enter your date of birth, in mm/dd/ format: "; echo " "; echo " "; echo " "; echo " "; goto begin; // if form submitted // process form input } else { starter: if (isset($_POST['cat'])) goto purr; // split date value into components $dateArr = explode('/', $_POST['dob']); // calculate timestamp corresponding to date value $dateTs = strtotime($_POST['dob']); // calculate timestamp corresponding to 'today' $now = strtotime('today'); // check that the value entered is in the correct format if (sizeof($dateArr) != 3) { die('ERROR: Please enter a valid date of birth'); } // check that the value entered is a valid date if (!checkdate($dateArr[0], $dateArr[1], $dateArr[2])) { die('ERROR: Please enter a valid date of birth'); } // check that the date entered is earlier than 'today' if ($dateTs >= $now) { die('ERROR: Please enter a date of birth earlier than today'); } // calculate difference between date of birth and today in days // convert to years // convert remaining days to months // print output $ageDays = floor(($now - $dateTs) / 86400); $ageYears = floor($ageDays / 365); $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30); echo "You are approximately $ageYears years and $ageMonths months old."; goto meow; } meow: if (!isset($_POST['dob'])) goto begin; if (!isset($_POST['cat'])) { echo " "; echo " Enter your kitten's name: "; echo " "; echo " "; echo " "; echo ""; } else { purr: $name_cat = $_POST['cat']; echo "Your Kitten is $name_cat"; $ender = 1; } if ($ender == 0) goto begin; first_step: ?> Ethan MySQL 5.1 PHP 5 Linux [Debian (sid)] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ No virus found in this message. Checked by AVG - www.avg.com Version: 10.0.1170 / Virus Database: 1435/3323 - Release Date: 12/18/10