Jump to content

genzedu777

Members
  • Posts

    266
  • Joined

  • Last visited

Everything posted by genzedu777

  1. Hi, I need some help here. I wld like to make active radio button on my ratings, but cant seem to get it. Appreciate anyone advice These are my codes <div style="margin-top: 10px;"> <span class="match_header">Arrange by</span> <label for="sort_tutor_total_rating"><input type="radio" name="sort" value="rating" id="sort_tutor_total_rating" <?php if($sort == 'rating'){ ?> checked="checked" <?php } ?> />Ratings</label> <label for="sort_tutor_rank"><input type="radio" name="sort" value="ranking" id="sort_tutor_rank" <?php if($sort == 'ranking'){ ?> checked="checked" <?php } ?> />Ranking</label> <label for="sort_tutor_assignment"><input type="radio" name="sort" value="assignments" id="sort_tutor_assignment" <?php if($sort == 'assignments'){ ?> checked="checked" <?php } ?> />Assignments</label> <label for="sort_tutor_id"><input type="radio" name="sort" value="join_date" id="sort_tutor_id" <?php if($sort == 'join_date'){ ?> checked="checked" <?php } ?> />Date Joined</label> </div> Picture.doc
  2. Hi all, I need help in setting multiple if commands in microsoft excel 2010. However after setting more than 2 IF commands, the system prompted me Tiers Equation Interest Rate 1st 20k Next 20k (20 - 40) Next 20k (40 - 60) Next 20k (60 - 80) More than 80k 1st 20k 20000 0.006 ADD INTEREST Next 20k 20001 40000 0.006 $ 120.00 ADD INTEREST Next 20k 40001 60000 0.005 $ 120.00 $ 100.00 ADD INTEREST Next 20k 60001 80000 0.005 $ 120.00 $ 100.00 $ 100.00 ADD INTEREST 80001 777494 0.005 $ 120.00 $ 100.00 $ 100.00 $ 100.00 ADD INTEREST Unlimited 777494 $3,818.189 Code =IF(D17<$B$5,(D17*$D$5),IF(AND(D17>=B6, D17<=C6),(((D17-20000)*D6)+E6))IF(AND(D17>=B6, D17<=C6),(((D17-20000)*D6)+E6))) "You have entered too many arguments for this function. To get help with this function, click OK to close this message. Then click the Insert Function button located to the left of the equal sign in your formula" And I seriously do not know how to use the Function command. It is unlike excel 2003, where it allows multiple IF commands. Need help here. Thanks
  3. Sorry, I really dont have much knowledge about this I see, so framework is actually practise among programmers?
  4. Hi guys, I just have a simple question. Recently I have come across framework, and realised from a few programmers that they are using Framework to assist them in creating websites, and it seems like most of the codes are provided. My question is, if framework is so useful, why are there still people coding from scratch? Thanks
  5. Hi mjdamato, The answer is yes. Appreciate your next advice. Perhaps you can take a look at our registration form, with that you might have a better understanding. http://www.championtutor.com/tutor_registration3.php Thanks
  6. Hi all, It always happens, after posting a few more follow-up answers, everyone stops replying me. It really makes me wonder, if my question is too complex or my explanation is vague. And if it is vague, I really don't mind explaining further...but please reply me. I need to submit my first phase project very soon. Thank you!!!
  7. Hi mjdamato, Please allow me to explain. There is a purpose for it when we conduct a search throughout our database, as there are at times companies would approach us for 'Pre-School' tutors irregardless of the teaching subjects. Hence, to have the levels' values checked is important to us. I have dropped you an enquiry in another thread to ask you about the functionality of using 2 while loops. It will be of great help if you can shed some light in that thread. I have been stucked for almost a week already. Thank you very much
  8. Hi mjdamato, Is it possible to help me out with these 2 while loops? I am still trying to figure out what had happened. I realised what is left in $subject_data = array(); is only the last value. For example, in subject_data array, there should be 3 values...Eng, Math and Sci However at the end day, subject_data array only keeps 'Sci', the other 2 subjects are missing - 'Eng', 'Math'. It seems like somehow it has been overwritten. I have done some troubleshooting, and realised it is only when I execute the 2nd while loop, while ($data1 = mysqli_fetch_array($sql1)), it will overwrite the values in subject_data array Do I need to store the results/values in subject_data array somewhere in another variable, before executing the 2nd while loop? while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { $levelCheckboxes .= createLevelCheckboxes($subject_data, $level_data 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { $levelCheckboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $levelCheckboxes .= createLevelCheckboxes($subject_data, $level_data, 5);
  9. Hi Nightslyr, I understand that in the 1st while loop, somehow the array will only keep the last value...so I am thinking if there is anyway that I can work it out to what I want to achieve. This is my query $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc));
  10. Hi ansharma, This is my function () function createLevelCheckboxes($subjectArray, $levelArray, $columns) { if(count($levelArray)==0) { return false; } $htmlOutput = ''; //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; foreach($levelArray as $data1) { //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<th colspan=\"{$columns}\" style=\"text-align:left;padding-top:15px;\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" type=\"checkbox\" {$checked} value=\"{$levelID}\">"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</th>\n"; $htmlOutput .= "</tr>\n"; } //Display each subject $recordCount = 0; foreach($subjectArray as $data) { //Increment counter $recordCount++; //Start new row if needed, 1/5 = R1 --> So create a new row if ($recordCount % $columns == 1) { $htmlOutput .= "<tr>\n"; } //Display the record $subjectID = $data['subject_level_id']; $subjectName = $data['subject_name']; $checked = ($data['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= " <td>\n"; $htmlOutput .= " <input name=\"subject_level[]\" class=\"subject_a\" type=\"checkbox\" {$checked}"; $htmlOutput .= " id=\"subject_level_{$subjectID}\" value=\"{$subjectID}\"/>\n"; $htmlOutput .= " <label for=\"subject_level_{$subjectID}\" class=\"subject_1\">{$subjectName}</label>\n"; $htmlOutput .= "</td>\n"; //Close row if needed, 5/5 = 0 --> So close the row if ($recordCount % $columns == 0) { $htmlOutput .= "</tr>\n"; } } //Close last row if needed if ($recordCount % $columns != 0) { $htmlOutput .= "</tr>\n"; } return $htmlOutput; }
  11. Hi harristweed, It's even worse after applying outside the loop. It is showing everything Initially it was... Level 1 Sci Level2 Sci Level3 Sci Now it is... Level 1 Math, Eng, Sci Level2 Math, Eng, Sci Level3 Math, Eng, Sci Correct example should be Level 1 Math Level 2 Eng Level 3 Sci And I realised you can't remove the $subject_data = array();, as it helps to store the correct value (math) into the correct level (level1) Any other advice? Can someone please enlighten me! Thank you
  12. Hi all, I am desperately in need of some help here. I have been troubleshooting these codes for days, and I have posted this similar question quite a couple of times, and there is no answer from anyone... I am really in a bad shape now. Could someone please enlighten me to my problem? I have created 2 while loops...apparently the 2nd while loop overwrites the 1st while loop record. Meaning to say...1st while loop generates values of 'Math' 'Eng' 'Chi' 'Sci' AND store it in $subject_data, createLevelCheckboxes($subject_data, $level_data, 5); Apparently, the 2nd while loop takes only the last record 'Sci' from $subject_data and continues the looping. Which gives me results like Level 1 Sci Level2 Sci Level3 Sci I would like to attain something like.... Level 1 Math Level2 Eng Level3 Chi Level4 Sci Is there any reset which I need to do? while($data = mysqli_fetch_array($sql)) { if($current_level_id != $data['level_id']) { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } while($data1 = mysqli_fetch_array($sql1)) //Iterate throug the DB results { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5);
  13. Hi mjdamato, Thanks for the detailed codes. However, if the user checks on Pre-School, it should not check all the subejcts in Pre-School. Pre-School checkbox will only be checked, and when it's checked, it doesnt affect the subjects under its level. Perhaps, that is the reason why I have arranged an additional table called 'tutor_selected_level' to faciliate this logic. Do you know how I should work it in your given codes? I am still currently figuring what your codes are...Thanks
  14. Hi, Could anyone give me some advice? As I am running out of time to submit this portion for my project...Thank you!
  15. Hi all, I need some help here. Currently I am using 2 functions. 1) To call out the 'academic levels' 2) To call out the 'subjects' which matches to the specific 'academic level' However, I am stucked in the codes. Please view my picture attachment, my question is, how do I assigned 'red box (Pre-School)' to 'red box (subjects)' and so on...What are the codes or tweaks that I should make so that it will look like 'what do I want to achieve.jpg' My process and execution $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $subjectCheckboxes .= createSubjectCheckboxes($subject_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $levelCheckboxes .= createLevelCheckboxes($level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $levelCheckboxes .= createLevelCheckboxes($level_data, 5); $subjectCheckboxes .= createSubjectCheckboxes($subject_data, 5); My functions function createLevelCheckboxes($levelArray, $columns) { if(count($levelArray)==0) { return false; } $htmlOutput = ''; foreach($levelArray as $data1) { //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<th colspan=\"{$columns}\" style=\"text-align:left;padding-top:15px;\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" type=\"checkbox\" {$checked} value=\"{$levelID}\">"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</th>\n"; $htmlOutput .= "</tr>\n"; } return $htmlOutput; } function createSubjectCheckboxes($subjectArray, $columns) { //Display each subject $recordCount = 0; foreach($subjectArray as $data) { //Increment counter $recordCount++; //Start new row if needed, 1/5 = R1 --> So create a new row if ($recordCount % $columns == 1) { $htmlOutput .= "<tr>\n"; } //Display the record $subjectID = $data['subject_level_id']; $subjectName = $data['subject_name']; $checked = ($data['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= " <td>\n"; $htmlOutput .= " <input name=\"subject_level[]\" class=\"subject_a\" type=\"checkbox\" {$checked}"; $htmlOutput .= " id=\"subject_level_{$subjectID}\" value=\"{$subjectID}\"/>\n"; $htmlOutput .= " <label for=\"subject_level_{$subjectID}\" class=\"subject_1\">{$subjectName}</label>\n"; $htmlOutput .= "</td>\n"; //Close row if needed, 5/5 = 0 --> So close the row if ($recordCount % $columns == 0) { $htmlOutput .= "</tr>\n"; } } //Close last row if needed if ($recordCount % $columns != 0) { $htmlOutput .= "</tr>\n"; } return $htmlOutput; } [attachment deleted by admin]
  16. Hi, I dont quite understand you. $query1 is generating 'levels' values, not 'subjects' values. Just want to understand where does the duplicated subjects come from...
  17. Hi mjdamato, So sorry to trouble you again, didn't expect you to reply to this thread, as I didn't want to tie you down by all my questions. I don't quite get you. How can I achieve it? Since I have 2 different queries ($query & $query1) while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; }
  18. Hi mjdamato, Really appreciate your patience and commitment in analyzing my database structure and working out the codes for me so professionally. Many thanks!! However I realised after executing the codes, the result is similar to what was given before. In fact, there is one missing table which was not added in the $query, that is tutor_selected_level. I am almost done in working through your previous given codes. Perhaps to minimize the overall hassles, could we still work on your previous given code? 1) I have managed to get what the users had selected in the parent boxes (Levels) checked. ie. Pre-School, Lower Pri, Upper Pri and Lower Secondary 2) Managed to list out all the children boxes (subjects) and get it checked in accordance to the user selections 3) One issue, all the subjects listed in the children boxes belongs to one parent level 'Others'. Strange The subjects in the levels are all the same. They are repeated subjects taken from 'Others' level. Makes me wonder what had happened. All the subjects belong to other levels are not shown. See example11.jpg Perhaps we could work around the below codes, just to retrieve out the correct subjects for the levels. Currently I am using 3 parameters in the function. I have used '2 while loops', not too sure have I done it correctly. Thanks function createLevelCheckboxes($subjectArray, $levelArray, $columns) { if(count($levelArray)==0) { return false; } $htmlOutput = ''; foreach($levelArray as $data1) { //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<td colspan=\"{$columns}\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" type=\"checkbox\" {$checked} value=\"{$levelID}\">"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</td>\n"; $htmlOutput .= "</tr>\n"; } //Display each subject $recordCount = 0; foreach($subjectArray as $data) { //Increment counter $recordCount++; //Start new row if needed, 1/5 = R1 --> So create a new row if ($recordCount % $columns == 1) { $htmlOutput .= "<tr>\n"; } //Display the record $subjectID = $data['subject_level_id']; $subjectName = $data['subject_name']; $checked = ($data['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= " <td>\n"; $htmlOutput .= " <input name=\"subject_level[]\" class=\"subject_a\" type=\"checkbox\" {$checked}"; $htmlOutput .= " id=\"subject_level_{$subjectID}\" value=\"{$subjectID}\"/>\n"; $htmlOutput .= " <label for=\"subject_level_{$subjectID}\" class=\"subject_1\">{$subjectName}</label>\n"; $htmlOutput .= "</td>\n"; //Close row if needed, 5/5 = 0 --> So close the row if ($recordCount % $columns == 0) { $htmlOutput .= "</tr>\n"; } } //Close last row if needed if ($recordCount % $columns != 0) { $htmlOutput .= "</tr>\n"; } return $htmlOutput; } $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level //$level_data = array(); //Temp array to hold all the records for a level // Line above is not actually not needed since it is defined in the IF statement below on the first record while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); [attachment deleted by admin]
  19. Okay. I have attached my DB. Thanks. As I was doing some trials and errors with the code. I managed to get the checkboxes of the level checked As you can see in example11.jpg Pre-School, Lower Pri, Upper Pri and Lower Secondary - the levels are checked. I have an issue, if you realised, the subjects in the levels are all the same. They are repeated subjects taken from 'Others' level. Makes me wonder what had happened. All the subjects belong to other levels are not shown. Really appreciate your help....Thank you so much <?php function createLevelCheckboxes($subjectArray, $levelArray, $columns) { if(count($levelArray)==0) { return false; } $htmlOutput = ''; foreach($levelArray as $data1) { //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<td colspan=\"{$columns}\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" type=\"checkbox\" {$checked} value=\"{$levelID}\">"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</td>\n"; $htmlOutput .= "</tr>\n"; } //Display each subject $recordCount = 0; foreach($subjectArray as $data) { //Increment counter $recordCount++; //Start new row if needed, 1/5 = R1 --> So create a new row if ($recordCount % $columns == 1) { $htmlOutput .= "<tr>\n"; } //Display the record $subjectID = $data['subject_level_id']; $subjectName = $data['subject_name']; $checked = ($data['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= " <td>\n"; $htmlOutput .= " <input name=\"subject_level[]\" class=\"subject_a\" type=\"checkbox\" {$checked}"; $htmlOutput .= " id=\"subject_level_{$subjectID}\" value=\"{$subjectID}\"/>\n"; $htmlOutput .= " <label for=\"subject_level_{$subjectID}\" class=\"subject_1\">{$subjectName}</label>\n"; $htmlOutput .= "</td>\n"; //Close row if needed, 5/5 = 0 --> So close the row if ($recordCount % $columns == 0) { $htmlOutput .= "</tr>\n"; } } //Close last row if needed if ($recordCount % $columns != 0) { $htmlOutput .= "</tr>\n"; } return $htmlOutput; } $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level //$level_data = array(); //Temp array to hold all the records for a level // Line above is not actually not needed since it is defined in the IF statement below on the first record while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); ?> [attachment deleted by admin]
  20. Hi all, Just to check if it is possible to have 2 while loops in a single code? Below are my codes. SQL code $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); PHP code (2 while loops) //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data1['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5);
  21. Hi mjdamato, Perhaps, just one question. I realised the objective for this $query is to match the numbers of selected subject_level_id to one tutor_id //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); Now I will need to match the numbers of selected level_ids to one tutor_id, from a new table called tutor_selected_level, could it mean that I have to recreate another query call $query2, so that I will not mess up $query's results? $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); I am not too sure if I have done the correct method, currently I have 2 while loop in this command //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level $level_data = array(); //Temp array to hold all the records for a level // Line above is not actually not needed since it is defined in the IF statement below on the first record while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5);
  22. Hi mjdamato, I will be more than willing to provide you a backup copy, but how do I send the entire database to you? By the way, just curious. Do you provide freelance programming? haha...
  23. Hi mjdamato, I just realised the checkboxes in the levels are not checked, my bad. I have missed out the tutor_selected_level.sql table, therefore I have added this new table, however I received some weird results. If you look into checkboxes.jpg, you will realize Pre-School, Lower Primary, Upper Primary and Lower Secondary appear, because these are the checkboxes which the user had selected. The rest of the levels like, A levels, IB, Uni etc are all missing. Another thing, the checkboxes are in fact not checked, but it has a comment of "type="checkbox" Any advice is greatly appreciated? Thanks I have added tslvl.level_id , INNER JOIN tutor_selected_level AS tslvl USING (level_id) //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, tslvl.level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) INNER JOIN tutor_selected_level AS tslvl USING (level_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); I have added foreach($levelArray as $data1), $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; function createLevelCheckboxes($levelArray, $columns) { if(count($levelArray)==0) { return false; } foreach($levelArray as $data1) { $htmlOutput = ''; //Display level header row $levelID = $levelArray[0]['level_id']; $levelName = $levelArray[0]['level_name']; $checked = ($data1['checked'] == 1) ? ' checked="checked"' : ''; $htmlOutput .= "<tr>\n"; $htmlOutput .= "<td colspan=\"{$columns}\">"; $htmlOutput .= "<input name=\"level[]\" type=\"checkbox\" id=\"level_{$levelID}\" value=\"{$levelID}\"> type=\"checkbox\" {$checked}"; $htmlOutput .= "<span class=\"zone_text_enlarge\"><label for=\"level_{$levelID}\">{$levelName}</label></span>"; $htmlOutput .= "</td>\n"; $htmlOutput .= "</tr>\n"; } [attachment deleted by admin]
  24. Hi jesirose, I understand where you are coming from, if you look carefully at the 4 pictures or tables... //The primary key for tutor_preferred_dlocation.sql is district_id, and that is the reason why I can link tutor_preferred_dlocation & tutor_preferred_district together, because they shared the same common key 1) tutor_preferred_dlocation (tutor_preferred_dlocation.jpg) 2) tutor_preferred_district (tutor_preferred_district.jpg) //The primary key for tutor_preferred_zlocation.sql is zone_id, and that is the reason why I can link tutor_preferred_zlocation & tutor_preferred_zone together, because they shared the same common key 3) tutor_preferred_zlocation (tutor_preferred_zlocation.jpg) 4) tutor_preferred_zone (tutor_preferred_zone.jpg) Now, my first question 1) Can I still link (1)(2) with (3)(4), is it possible? 2) If it's possible, then how? I have read through LEFT JOIN & RIGHT JOIN, even ON. I don't seem to find an answer, the common denominator is still...you need a common primary key to link the tables together. Please correct me if I am wrong as I am still new in php and sql, would appreciate any advice from you. Thanks
  25. Hi, I am not too sure if I have used the right command, I am using print_r($sql), to view my executed results, but apparently I received mysqli_result Object ( ) , any advice? Thanks $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die(mysqli_error($dbc)); //Run query $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tpd.district_id, tpd.district_name, tpz.zone_id, tpz.zone_name FROM tutor_preferred_district AS tpd INNER JOIN tutor_preferred_dlocation AS tpdl USING (district_id) INNER JOIN tutor_preferred_zlocation AS tpzl USING (tutor_id) INNER JOIN tutor_preferred_zone AS tpz USING (zone_id) WHERE tpdl.tutor_id = '{$tutor_id}'"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); print_r($sql);
×
×
  • 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.