Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,034 members, 8,001,169 topics. Date: Wednesday, 13 November 2024 at 05:09 AM |
Nairaland Forum / Science/Technology / Webmasters / Php/mysql Gurus, Please Help Solve This Problem... (1042 Views)
Web Gurus, Please Which Blogger Template Is This Site Using? / Lets Talk About How Blogging Can Help Solve Nigeria Unemployment. / Is This Problem From My Firefox Or Google? (pic Attached) (2) (3) (4)
Php/mysql Gurus, Please Help Solve This Problem... by Webhost(m): 11:45pm On Dec 11, 2015 |
Now I need urgent help from php masters; I have a table named symptoms with 2 columns (id) and (symptoms) for example id Symptoms 1 I have an head ache 2 My anckle aches 3 My eyes hurt 4 I am vomiting once every day 5 I have an eczema these symtopms will be on the home page in form of a question with a check box in front of each one. Now if a user selects 1,2 and 5, nd submits, the next page will bring a message saying "you have Malaria" 1,2,4 and 5 will say "you have Typhoid" Selecting 1 3 and 5 will say "you have Measles" etc. I believe you get the gist. Just like a simple symptom checking app. How do I go about this? using the table ids above? Thanks |
Re: Php/mysql Gurus, Please Help Solve This Problem... by ps3o(m): 12:44am On Dec 12, 2015 |
Webhost: I'm a professional web developer. should you need help? call/SMS/WhatsApp 07031175291 |
Re: Php/mysql Gurus, Please Help Solve This Problem... by DualCore1: 6:33am On Dec 12, 2015 |
Create a second table called "rules" with the following structure table: rules fields: id, symptoms, sickness the "id" field is an auto increment field. The "symptoms" field is a varchar field that will hold a json string of all the symptoms making up one sickness, the "sickness" field will hold the name of the sickness. So, an example of one of the data records in this new table will be: id: 1 symptoms: ["1", "2", "5"] sickness: malaria You can have as many rulesets as you want like the one above with different set of symptoms and disease. Now the processing. On the first page, display all the symptoms as you have said with checkboxes. For reference purpose let us name your checkboxes "symptoms[]" On the form processor, the page that handles the user request and tells the user what sickness they have... it should have this kind of flow: //get the list of "checked" symptoms from the symptoms[] array that has come in through the form's POST data. //now you have an array of all the checked symptoms, let's call it $user_symptoms //do a database query of your rules table "select * from rules" //traverse through the result of the db query discarding any rulesets that do not have the same amount of checked symptoms first, like this: foreach(put appropriate code here depending on how you query db){ $db_symptoms = $result['symptoms'] //i am assuming your db query result has been placed into the $result array. //now you have gotten a json formatted string of symptoms, convert this to an array $symptoms_array = json_decode($db_symptoms, 1); //up to this point we now have 2 arrays. The array of the checked symptoms ($user_symptoms) and that of the symptoms for each ruleset ($symptoms_array) //next compare both arrays, if both arrays are not the same in length, discard. if(count($symptoms_array) == count($user_symptoms)){ //both arrays are the same in length, now check to find match the two arrays, they must be exact $match = array_diff($symptoms_array, $user_symptoms) //if there is a match, the $match will hold an array with no elements if(count($match) == 0){ //you have a match echo "you dey suffer from ".$result['sickness']; } } } I hope you get the logic, others may have a better logic but do not take the option of deciding the sickness with decision constructs as opposed to creating a "rules" table. If you use decision constructs, for each sickness you want to profile you will need to write a new set if if/elseif/else block. But with my suggested method above, you just write this code once and add new sicknesses to your database without needing to write any new code. 1 Like |
Re: Php/mysql Gurus, Please Help Solve This Problem... by DualCore1: 6:39am On Dec 12, 2015 |
ps3o:Everything always has to be about the money, right? Put your passion above your profession and you won't need to advertise. 2 Likes |
Re: Php/mysql Gurus, Please Help Solve This Problem... by FincoApps(m): 8:41am On Dec 12, 2015 |
DualCore1: Nice one mehn |
Re: Php/mysql Gurus, Please Help Solve This Problem... by Webhost(m): 2:52pm On Dec 12, 2015 |
@DualCore1, Thank you VERY MUCH. I have seen some of your previous posts, you are really good. I will try it out and update here the result. May God bless you real good. |
Re: Php/mysql Gurus, Please Help Solve This Problem... by ps3o(m): 4:15pm On Dec 12, 2015 |
DualCore1:Did I ever mention money in my last post? Read in between the lines before u quote any of my posts. |
Re: Php/mysql Gurus, Please Help Solve This Problem... by spikesC(m): 4:25pm On Dec 13, 2015 |
DualCore1: Wouldn't this be an overhead? Selecting all the rules and comparing in code? why don't he use the power of RDBMS and do a one to many relationship. Or even when using JSON, filter the results with a WHERE clause. The only problem is, he has to make sure the data is always in a predetermined format (example; symptom IDs must be in ascending order) |
Re: Php/mysql Gurus, Please Help Solve This Problem... by DualCore1: 7:09pm On Dec 13, 2015 |
spikesC:You can tweak the code as desired or write a full snippet so he can understand. 1 Like |
Re: Php/mysql Gurus, Please Help Solve This Problem... by eidesk(m): 12:38pm On Dec 14, 2015 |
Closed - Out of date |
(1) (Reply)
'bandwidth Limit Exceeded' When Trying To Access My Website / Mark Zuckerberg Message To Nigerians.. Photos / Get The Real IT Skills And Fast Track Your Profession
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 39 |