php - display different tables based on a selected checkbox value for a current user in session -


when user registers there multiple healthcondition checkboxes user select ever applies them. allowed select 1 or more condition.

i want set query when user logs in automatically see table showing foodoptions based on selected healthcondition/s upon registeration. able store these values in database i'm not sure how go retrieving these values , setting specific condition pull foods each of checkboxes database depending on on ever stored in database....

currently healthcondition stored diabetes, high cholesterol etc under field name healthcondition in member table. totally new , stressed out... please me ....

please select of following conditions apply you: diabetes type1
diabetes type2
anemia
high cholesterol
pregnant
none of above

this code inserts data database

if(isset($_post['healthcondition'])) {                            $healthcondition = implode(",", $_post['healthcondition']);                           } else {                           $healthcondition = "";                           }                           echo "healthcondition".$healthcondition;           $con = mysql_connect("localhost","root","") or die ("could not connect db server");         //name of database          $db_selected = mysql_select_db("srsnutriguidedb", $con) or die("could not locate db");          //addperson sql holds insert sql query string          $addpersonsql = "insert tblmember(gender,agegroup, firstname, lastname, address, contact, email,  username,password,weight,height,bloodtype,healthcondition,stress,exercise,water,smoke,alcohol,accstatus,memberpic)                           values('$gender','$agegroup', '$first','$last', '$address','$contact','$email', '$user', md5('$pw1'),'$weight','$height', '$bloodtype', '$healthcondition','$stress','$exercise','$water','$smoke','$alcohol','na', '')"                           or die ("unable insert data person table"); 

this problem is

$result = mysql_query("select tblmember.healthcondition,foodname, serving_size, calories, cholesterol, sodium, protein, total_carbohydrates, total_fat                         tblhealthcondition inner join tblmemberhealthcondition on tblhealthcondition.healthconditionid = tblmemberhealthcondition.healthconditionid,                              tblmember inner join tblhealthcondition on tblmember.healthcondition = tblhealthcondition.healthcondiiton,                             tblfoodoptions inner join tblhealthconditionfoods on tblfoodotpions.foodid = tblhealthconditionfoods.foodid                        tblmember.username = '".$_session['musername']."'", $con) or die("cannot select member database...");              if(isset($_post['healthcondition'])      foreach($_post['healthcondition'] $healthcondition)  {                   echo "<table width='100%' border='4'>             <caption>your food options</caption>             <thead><tr>                 <th>foodname</th><th>serving_size</th><th>calories</th><th>cholesterol</th><th>sodium</th><th>protein</th><th>total_carbohydrates</th><th>total_fat</th>             </tr></thead>             <tbody>";     while($row = mysql_fetch_array($result))         {             echo "<tr>";              echo "<td>".$row['foodname']."</td>";             echo "<td>".$row['serving_size']."</td>";             echo "<td>".$row['calories']."</td>";             echo "<td>".$row['cholesterol']."</td>";             echo "<td>".$row['sodium']."</td>";             echo "<td>".$row['protein']."</td>";             echo "<td>".$row['total_carbohydrates']."</td>";             echo "<td>".$row['total_fat']."</td>";                 echo "</tr>";         }     echo "</tbody></table>";             } 

food options foodnameserving_sizecaloriescholesterolsodiumproteintotal_carbohydratestotal_fat "; while($row = mysql_fetch_array($result)) { echo ""; echo "".$row['foodname'].""; echo "".$row['serving_size'].""; echo "".$row['calories'].""; echo "".$row['cholesterol'].""; echo "".$row['sodium'].""; echo "".$row['protein'].""; echo "".$row['total_carbohydrates'].""; echo "".$row['total_fat'].""; echo ""; } echo ""; break; case "pregnant": echo " food options foodnameserving_sizecaloriescholesterolsodiumproteintotal_carbohydratestotal_fat "; while($row = mysql_fetch_array($result)) { echo ""; echo "".$row['foodname'].""; echo "".$row['serving_size'].""; echo "".$row['calories'].""; echo "".$row['cholesterol'].""; echo "".$row['sodium'].""; echo "".$row['protein'].""; echo "".$row['total_carbohydrates'].""; echo "".$row['total_fat'].""; echo ""; } echo ""; } ?>

generally simple data retrieval problem. want follow these general steps:

  1. retrieve current user's selection (using select query in db mysql)
  2. select specific data want display other table (such "select * foodsuggestions condition = '{$usercondition}'")
  3. present information in meaningful way.

you need go , read tutorials on databases , data structure, appears you're not familiar them, , difficult explain or understand without knowledge.

university of reddit has decent intro here

edit:

if data not need persist, can use like:

start_session(); $_session['healthchoice'] = $_request['healthchoice']; 

then:

switch ($_session['healthchoice']) {     case "option1":         // stuff here         break;      case "option2":         // stuff here         break; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -