Jump to content

scallywag05

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

scallywag05's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi i need to initialise an array of months and days of the month so that when a user chooses a specific month an sql query runs selecting data from the database about the specified month ie: $month =(1=>"january"...................) $sql = Select * from table where username=$username and date='2006-MONTH-' the data is stored in the database in this form '2006-M-D', how do i depending on [b][!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]month only[!--colorc--][/span][!--/colorc--][/b] display the data?
  2. yeah i looked at it but im not really familiar with php so didnt really understand what your code was doing.
  3. Barand, I posted a copy of both the form and the php to show the $POST#_variable
  4. The code here is just displaying the values to the user. Th user then clicks a button to plot the graph after viewing the results. I was going to use jpGraph to do this but dont really know how to get the values and months to display. is there a way instead of having to display the values it will automatically plot the graph depending on what the user selects, both variable and monthly. Thanks for all the help its greatly appreciated.
  5. Here is the code for the form: [code]<form name="form1" method="post" action="assessment2.php">   <p><font color="#FF0000" face="Geneva, Arial, Helvetica, sans-serif"><strong>Please     select which of the options below you wish to analyse:</strong></font></p>   <ul>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Cholesterol         <input name="variable[cholesterol_value]" type="checkbox" id="variable[cholesterol]" value="checkbox">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Blood Pressure:         Systolic         <input name="variable[bp_value]" type="checkbox" id="variable[bp_value]" value="checkbox">         <em>ie: <font color="#FF0000">120</font>/80</em></strong></font></h3>     </li>     <li>       <h3><strong><font face="Geneva, Arial, Helvetica, sans-serif">Blood Pressure:         Diastolic </font></strong><em><strong><font face="Geneva, Arial, Helvetica, sans-serif">         <input name="variable[bp_value2]" type="checkbox" id="variable[bp_value2]" value="checkbox">         ie: 120/<font color="#FF0000">80</font></font></strong></em></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong> BMI         <input name="variable[bmi_value]" type="checkbox" id="variable[bmi_value]" value="checkbox">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Weight         <input name="variable[weight_value]" type="checkbox" id="variable[weight_value]" value="checkbox">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong> Calories         Burnt         <input name="variable[calories_value]" type="checkbox" id="variable[calories_value]" value="checkbox">         </strong></font></h3>     </li>   </ul>   <p><font color="#FF0000" face="Geneva, Arial, Helvetica, sans-serif"><strong>Please     select the period you would like to track the option you selected over:<br>     <font color="#000000"><em>NOTE! you must select more than one:</em></font>     </strong></font></p>   <table width="25%" border="1">     <tr>       <td width="62%" bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">January</font></strong></div></td>       <td width="38%"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[jan]" type="checkbox" id="month[jan]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">February           </font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[feb]" type="checkbox" id="month[feb]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">March           </font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[mar]" type="checkbox" id="month[mar]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">April</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[apr]" type="checkbox" id="month[apr]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">May</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[may]" type="checkbox" id="month[may]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">June</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[june]" type="checkbox" id="month[june]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">July</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[july]" type="checkbox" id="month[july]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">August           </font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[aug]" type="checkbox" id="month[aug]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">September</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[sept]" type="checkbox" id="month[sept]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">October</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[oct]" type="checkbox" id="month[oct]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">November</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[nov]" type="checkbox" id="month[nov]" value="checkbox">           </font></div></td>     </tr>     <tr>       <td bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">December</font></strong></div></td>       <td><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="month[dec]" type="checkbox" id="month[dec]" value="checkbox">           </font></div></td>     </tr>   </table>   <p>     <input type="submit" name="Submit" value="View Personal Assessment">   </p> </form>[/code] And then the php that the form calls: [code]         $mysqlserver = "localhost";                                 $user_id = "****";                                 $user_pw = "****";                                 $database_name = "database"; $username = $_SESSION['username']; $month = array (1=>"jan","feb","mar","apr","may","june","july","aug","sept","oct","nov","dec"); foreach ($_POST['month'] as $value=> $dmy){     echo "<li>$value</li>\n";     } if($username == '') # if form incomplete {     print "<p>Please Complete fields marked with an (*) as these are REQUIRED</p>";     print '<p><a href="' . $_SERVER['HTTP_REFERER'] . '">Go back to form</a></p>'; } else {     // connect to the MySQL and select database     $db1 = mysql_connect($mysqlserver, $user_id, $user_pw );     mysql_select_db($database_name ,$db1);          if($db1===false)     {             print "\n<br>Unable to open database";             die(1);     } // end if unable to open db    ?> <?php echo "<h2>The variables and the dates you chose are as follows:</h2>"; $curr_month = date('Y-m'); $sql2 = "SELECT COUNT(*) FROM pertrack WHERE DATE_FORMAT(date, '%Y-%m') = '$curr_month'"; $res = mysql_query($sql2); if (mysql_result($res,0)== 0) {        echo "No records this month"; } else{         if (isset($_POST['variable'])) {                 foreach ($_POST['variable'] as $k => $dmy) {                     echo '<ul><li><h3><strong>'.$k . '</strong></h3></ul></li>';                     $sql = "SELECT * FROM pertrack WHERE username='$username'";                     $result = mysql_query($sql, $db1);                         while($row=mysql_fetch_assoc($result)) {                         echo '<ul><li>Value:'.$row["$k"]."<br></li></ul>";                      }                                      }             } }     mysql_close($db1); }// end if no form submitted ?> [/code]
  6. Hi, Basically my form goes like this: Variable one - checkbox Variable two - checkbox. There are 5 checkboxes in total and you can choose more than one. Then in order to draw a graph the user then selects the months they want to see the results for, ie: Jan - checkbox Feb - checkbox Mar - checkbox....... What i want is that when the user picks the variables and the months to track a script will run that checks the databse for values of these variables for the specific months. my first problem was checking to see if there were values, as i have set up an array for the months as $month(1=>'jan', 'feb'........) and the databse has date stored as 0000-00-00, then how was i going to check if there were values entered for these dates and how to then display them in a graph!!!! Bit of a dilema......can you help me please!
  7. Thanks, I added the code you gave me but i want to run another piece of code that if there are values for that month for the variable selected it outputs them, ive attached the code maybe you can see where im going wrong. thanks for the help as you can tell i dont really know much about php yet! [code]$curr_month = date('Y-m-d'); $sql2 = "SELECT COUNT(*) FROM pertrack WHERE DATE_FORMAT(date, '%Y-%m-%d') = '$curr_month'"; $res = mysql_query($sql2); if (mysql_result($res,0)== 0) {        echo "No records this month"; } else{         if (isset($_POST['variable'])) {                 foreach ($_POST['variable'] as $k => $dmy) {                     echo '<ul><li><h3><strong>'.$k . '</strong></h3></ul></li>';                     $sql = "SELECT * FROM pertrack WHERE username='$username'";                     $result = mysql_query($sql, $db1);                         while($row=mysql_fetch_assoc($result)) {                    echo '<ul><li>Value:'.$row["$k"]."<br></li></ul>";                      }                 }             } }[/code]
  8. Hi, I have set up a form which displays months of the year as checkbox values and i want to when the user clicks on, for example january, to run an sql query that checks for entries on that date, but my array is set up as $month(jan, feb.....) and my sql database has date entries as 0000-00-00. How can i check depending on what the user clicks if there are entries for this month? Thanks
  9. What exactly is baaChart? im not really familiar with php. I have created a form which allows users to select 2 options and also months in which they want the options to be displayed. i want php to pull the data from the database and display it in a graph within a html page. i have installed jpGraph but dont really understand how to draw a graph and embed it within a html page at run time where each graph will be different depending on what the user selects? any help would be great. thanks
  10. Im trying to pull data from my MySQL database that the user selects and want to display it in a graph for trend analysis. Does anyone know how using PHP I can do this? Thanks
  11. Hi, Ive created a form with options for drawing a graph assessing 2 variables. I was just wondering how i would create the php that would call the values of the selected variables from the sql database depending on the option chosen and for the month selected,the months are set up as check boxes. I was going to use jpGraph to draw the graph but am not to sure how to embed the graph within a php that contains headers and html. the code for my form is: [code]<form name="form1" method="post" action="assessment2.php">   <p><font color="#FF0000" face="Geneva, Arial, Helvetica, sans-serif"><strong>Please     select one of the options below to analyse your personal log:</strong></font></p>   <ul>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Cholesterol         <font color="#FF0000">&amp;</font> Blood Pressure         <input type="radio" name="option" value="Chol_Blood">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong> BMI <font color="#FF9900">&amp;</font>         Weight         <input type="radio" name="option" value="BMI_Weight">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong> Calories         Burnt <font color="#FF0000">&amp;</font> Blood Pressure         <input type="radio" name="option" value="Calories_Blood">         </strong></font></h3>     </li>     <li>       <h3><font face="Geneva, Arial, Helvetica, sans-serif"><strong> Calories         Burnt <font color="#FF9900">&amp;</font> BMI         <input type="radio" name="option" value="Calories_BMI">         </strong></font></h3>     </li>   </ul> <p><font color="#FF0000" face="Geneva, Arial, Helvetica, sans-serif"><strong>Please     select the period you would like to track the option you selected over:<br>     <font color="#000000"><em>NOTE! you can select more than one:</em></font>     </strong></font></p>   <table width="25%" border="1">     <tr>       <td width="62%" bgcolor="#66FFCC"> <div align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif">January</font></strong></div></td>       <td width="38%"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif">           <input name="jan" type="checkbox" id="jan" value="checkbox">           </font></div></td>     </tr>     <tr> [/code]
  12. Thanks very much for the quick response. I tried the code there and it works perfectly. thank you very much.
  13. [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]here is the code for the form:[!--colorc--][/span][!--/colorc--][code] <form name="calories" method="post" action="../cgi-bin/cb.php">   <p align="left"><font color="#FF0000" face="Geneva, Arial, Helvetica, sans-serif"><strong>Convert     Kilograms <em>(kg)</em>:     <input type="text" name="kg" ONKEYUP="document.calories.pounds.value = 2.20*document.calories.kg.value"  id="kg">     to:     <input name="pounds" type="text" id="pounds" disabled>     Pounds <em>(lbs)</em></strong></font></p>   <p align="left"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Please     enter your weight:</strong>     <input name="weight" type="text" id="weight" size="10">     <em>lbs</em></font></p>   <p align="left"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Age:</strong>     <input name="age" type="text" id="age" size="10">     </font></p>   <p align="left"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Sex:</strong>     Male     <input name="sex" type="radio" value="Male" checked>     Female     <input type="radio" name="sex" value="Female">     </font></p>   <h3 align="left"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Activities     <em>(per week)</em>: Week beginning: </strong></font><font face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#009933">Todays     Date:</font>     <INPUT type="text"  name="date" size=25 maxlength=25 value="Loading">     </strong></font></h3>   <p align="left"><strong><font face="Geneva, Arial, Helvetica, sans-serif"><em>Please     select the activities and <font color="#FF0000">one duration for each</font>,     in the table below.</em></font></strong></p>   <table width="57%" height="277" border="1">     <tr>       <td width="57%"><div align="center"><strong><font face="Geneva, Arial, Helvetica, sans-serif">Activity</font></strong></div></td>       <td width="8%"><div align="center"></div></td>       <td width="35%"><div align="center"><strong><font face="Geneva, Arial, Helvetica, sans-serif">Duration</font></strong></div></td>     </tr>     <tr>       <td>Aerobics - low impact</td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="aerobics-l" value="aerobics-low impact">         </div></td>       <td><input name="duration1" type="text" id="duration1" size="10">         hours</td>     </tr>     <tr>       <td>Aerobics - high impact</td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="aerobics-h" value="aerobics-high impact">         </div></td>       <td><input name="duration2" type="text" id="duration17" size="10">         hours</td>     </tr>     <tr>       <td>Bicycling, &lt;10mph, leisure</td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="cycling-l" value="cycling-leisure">         </div></td>       <td><input name="duration3" type="text" id="duration18" size="10">         hours</td>     </tr>     <tr>       <td>Bicycling, &gt;20mph, racing<br></td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="cycling-h" value="cycling-racing">         </div></td>       <td><input name="duration4" type="text" id="duration4" size="10">         hours</td>     </tr>     <tr>       <td>Jogging (10 minute mile, 6mph)<br></td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="jogging" value="jogging">         </div></td>       <td><input name="duration5" type="text" id="duration19" size="10">         hours </td>     </tr>     <tr>       <td>Golf (carrying clubs)</td>       <td><div align="center">           <input name="activity[]" type="checkbox" id="golf" value="golf">         </div></td>       <td><input name="duration6" type="text" id="duration20" size="10">         hours</td>     </tr>   </table>   <p align="left"><font face="Geneva, Arial, Helvetica, sans-serif">     <input type="submit" name="Submit" value="Calculate Calories Burnt">     </font></p> </form> [/code] [color=#FF0000]the code for the php the form calls is the following: [code] $activity = array("aerobics-low impact", "aerobics-high impact", "cycling-leisure", "cycling-racing","jogging","golf","Light housework","running-(12min mile)","running-cross country","football","squash","swim-20m/min","swim-40m/min","tai-chi","walking-slow pace","walking-brisk pace"); $activity = $_REQUEST['activity']; $duration1 = $_REQUEST['duration1']; $duration2 = $_REQUEST['duration2']; $duration3 = $_REQUEST['duration3']; $duration4 = $_REQUEST['duration4']; $duration5 = $_REQUEST['duration5']; $duration6 = $_REQUEST['duration6']; $duration7 = $_REQUEST['duration7']; $duration8 = $_REQUEST['duration8']; $duration9 = $_REQUEST['duration9']; $duration10 = $_REQUEST['duration10']; $duration11 = $_REQUEST['duration11']; $duration12 = $_REQUEST['duration12']; $duration13 = $_REQUEST['duration13']; $duration14 = $_REQUEST['duration14']; $duration15 = $_REQUEST['duration15']; $duration16 = $_REQUEST['duration16']; if($username == '' || $weight == ''|| $age== ''|| $sex ==''||$date='') # if form incomplete {     print "<p>Please Complete fields marked with an (*) as these are REQUIRED</p>";     print '<p><a href="' . $_SERVER['HTTP_REFERER'] . '">Go back to form</a></p>'; } else {     // connect to the MySQL and select database     $db1 = mysql_connect($mysqlserver, $user_id, $user_pw );     mysql_select_db($database_name ,$db1);          if($db1===false)     {             print "\n<br>Unable to open database";             die(1);     } // end if unable to open db        } ?> </p> <form name="form1" method="post" action="">   <table width="68%" border="1">     <tr>       <td width="37%"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Activities</strong></font></div></td>       <td width="17%"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Duration</strong></font></div></td>       <td width="46%"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>Calories           Burnt</strong></font></div></td>     </tr>     <tr>       <td>         <?php               if ( ! empty( $activity)  ) {                foreach ( $activity as $value ) {             print "<li>$value\n<br>";                    }                print " ";                }                          else{                 print "You did not select an activity!!";                 }            ?>       </td>       <td>         <?php  //if statements to ensure that if a duration is filled in by                 //user it is displayed in the output table                      if (! empty($duration1)) {                    print"<li>$duration1 hours\n<br>";                   }                 else{                    $duration1= NULL;                 }                              if ( ! empty($duration2)) {                    print"<li>$duration2 hours\n<br>";                   }                 else{                     $duration2= NULL;                 }                              if ( ! empty($duration3)) {                    print"<li>$duration3 hours\n<br>";                   }                 else{                         $duration3= NULL;                 }                              if ( ! empty($duration4)) {                        print"<li>$duration4 hours\n<br>";                   }                 else{                  $duration4= NULL;                     }                          if ( ! empty($duration5)) {                    print"<li>$duration5 hours\n<br>";                   }                 else{                     $duration5= NULL;                 }                              if ( ! empty($duration6)) {                    print"<li>$duration6 hours\n<br>";                   }                 else{                     $duration6= NULL;                 }                              if ( ! empty($duration7)) {                    print"<li>$duration7 hours\n<br>";                   }                 else{                     $duration7= NULL;                 }                              if ( ! empty($duration8)) {                    print"<li>$duration8 hours\n<br>";                   }                 else{                         $duration8= NULL;                 }                                       if ( ! empty($duration9)) {                    print"<li>$duration9 hours\n<br>";                   }                 else{                         $duration9= NULL;                 }                              if ( ! empty($duration10)) {                    print"<li>$duration10 hours\n<br>";                   }                 else{                         $duration10= NULL;                 }                                               if ( ! empty($duration11)) {                    print"<li>$duration11 hours\n<br>";                   }                 else{                         $duration11= NULL;                 }                              if ( ! empty($duration12)) {                    print"<li>$duration12 hours\n<br>";                   }                 else{                         $duration12= NULL;                 }                                                            if ( ! empty($duration13)) {                    print"<li>$duration13 hours\n<br>";                   }                 else{                        $duration13= NULL;                 }                                   if ( ! empty($duration14)) {                    print"<li>$duration14 hours\n<br>";                   }                 else{                    $duration14= NULL;                 }                                           if ( ! empty($duration15)) {                        print"<li>$duration15 hours\n<br>";                                   }                 else{                    $duration15= NULL;                 }                                           if (! empty($duration16)) {                    print"<li>$duration16 hours\n<br>";                   }                 else{                    $duration16 = NULL;                 }         ?>       </td>       <td>       <?php                      if((!empty($duration1)) && (!empty($activity[0])))             {               $sql = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='aerobics-low impact'";             $result = mysql_query($sql, $db1);                          while($row=mysql_fetch_array($result)) {                      echo("<li>".$row["caloriesBurnt"]*$duration1*$weight."<br>");                         }             }             else             {             print " ";             }                      if((!empty($duration2)) && (!empty($activity[1])))             {             $sql2 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='aerobics-high impact'";             $result2 = mysql_query($sql2, $db1);                          while($row=mysql_fetch_array($result2)) {                      echo("<li>".$row["caloriesBurnt"]*$duration2*$weight."<br>");                     }                 }             else             {             print " ";             }                      if((!empty($duration3)) && (!empty($activity[2])))         {               $sql3 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='cycling-leisure'";             $result3 = mysql_query($sql3, $db1);                          while($row=mysql_fetch_array($result3)) {                      echo("<li>".$row["caloriesBurnt"]*$duration3*$weight."<br>");                     }                 }             else             {         print " ";             }                      if((!empty($duration4)) && (!empty($activity[3])))             {               $sql4 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='cycling-racing'";             $result4 = mysql_query($sql4, $db1);                          while($row=mysql_fetch_array($result4)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration4*$weight."<br>");                                     }                 }             else             {             print " ";             }                                       if((!empty($duration5)) && (!empty($activity[4])))             {               $sql5 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='jogging'";             $result5 = mysql_query($sql5, $db1);                          while($row=mysql_fetch_array($result5)) {                      echo("<li>".$row["caloriesBurnt"]*$duration5*$weight."<br>");                         }                 }             else             {             print " ";             }                          if((!empty($duration6)) && (!empty($activity[5])))             {               $sql6 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='golf'";             $result6 = mysql_query($sql6, $db1);                          while($row=mysql_fetch_array($result6)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration6*$weight."<br>");                                      }                 }             else             {             print " ";             }                          if((!empty($duration7)) && (!empty($activity[6])))             {               $sql7 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='Light housework'";             $result7 = mysql_query($sql7, $db1);                          while($row=mysql_fetch_array($result7)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration7*$weight."<br>");                              }                 }             else             {             print " ";             }                          if((!empty($duration8))&&(!empty($activity[7])))             {               $sql8 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='running-(12min mile)'";             $result8 = mysql_query($sql8, $db1);                          while($row=mysql_fetch_array($result8)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration8*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration9))&&(!empty($activity[8])))             {               $sql9 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='running-cross country'";             $result9 = mysql_query($sql9, $db1);                          while($row=mysql_fetch_array($result9)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration9*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration10))&&(!empty($activity[9])))             {               $sql10 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='football'";             $result10 = mysql_query($sql10, $db1);                          while($row=mysql_fetch_array($result10)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration10*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration11))&&(!empty($activity[10])))             {               $sql11 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='squash'";             $result11 = mysql_query($sql11, $db1);                          while($row=mysql_fetch_array($result11)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration11*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration12))&&(!empty($activity[11])))             {               $sql12 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='swim-20m/min'";             $result12 = mysql_query($sql12, $db1);                          while($row=mysql_fetch_array($result12)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration12*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration13))&&(!empty($activity[12])))             {               $sql13 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='swim-40m/min'";             $result13 = mysql_query($sql13, $db1);                          while($row=mysql_fetch_array($result13)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration13*$weight."<br>");                     }                 }             else             {             print " ";             }             if((!empty($duration14))&&(!empty($activity[13])))             {               $sql14 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='tai-chi'";             $result14 = mysql_query($sql14, $db1);                          while($row=mysql_fetch_array($result14)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration14*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration15))&&(!empty($activity[14])))             {               $sql15 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='walking-slow pace'";             $result15 = mysql_query($sql15, $db1);                          while($row=mysql_fetch_array($result15)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration15*$weight."<br>");                     }                 }             else             {             print " ";             }                          if((!empty($duration16))&&(!empty($activity[15])))             {               $sql16 = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='walking-brisk pace'";             $result16 = mysql_query($sql16, $db1);                          while($row=mysql_fetch_array($result16)) {                      echo("<li> ".$row["caloriesBurnt"]*$duration16*$weight."<br>");                     }                 }             else{             print " ";             }                 mysql_close($db1);       ?>       </td>     </tr>     <tr>       <td colspan="2"><div align="center"><font face="Geneva, Arial, Helvetica, sans-serif"><strong>TOTAL           CALORIES BURNT:</strong></font></div></td>       <td><?php       ?></td>     </tr>   </table>    </form> </body> [/code] Its a bit long but it works to a point. thanks
  14. Hi, Im using PHP to create a form which has the following components: Check Buttons = $activity[] Text fields = $duration1, $duration2...etc The user clicks the activity and enters a duration for each. I have a series of if..else statements that when the user fills in a duration and clicks the activity check box an sql query is run. Here is an example of the code: [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--] if((!empty($duration1)) && (!empty($activity[0]))) { $sql = "SELECT caloriesBurnt FROM caloriesburnt WHERE Activity='aerobics-low impact'"; $result = mysql_query($sql, $db1); while($row=mysql_fetch_array($result)) { echo("<li>".$row["caloriesBurnt"]*$duration1*$weight."<br>"); } } else { print " "; }[!--colorc--][/span][!--/colorc--] there are 16 activities in all and when the user clicks on simultaneous boxes,ie. 1,2,3,4,5 it returns a value for each activity ok but when the user for example clicks the first box and doesnt click another box until activity 10 it only calculates activity1. Is there a way i can calculate all activites no matter what order they are selected? thanks for the help
×
×
  • 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.