ceci Posted March 31, 2010 Share Posted March 31, 2010 Hi. I have two tables. One table with pain_meds and the other with diabetes_meds. I want to dynamically generate a table that displays a row for each Diabetes med for every pain_med. For example, for the Amaryl diabetes med there are 5 possible pain_meds (oxycode,Vicodin,ultram,morphine) that it interacts with. The same is true for Avandaryl and Byetta. For a better visual I'll try to attach a screenshot of the desired output. mysql> select dname from diabetes_med; +-------------------------------+ | dname | +-------------------------------+ |Amaryl | |Avandaryl | |Byetta | +-------------------------------+ 2 rows in set (0.00 sec) mysql> select drug_name from pain_meds; +------------------------+----------+ | drug_name | +------------------------+----------+ | oxycode | | Vicodin | | ultram | | morphine | +------------------------+----------+ Here is what I got so far but I can't seem to get it to work. I hope you can help me out. Thanks in advance. $diabetes_med = mysql_query("select dname from diabetes_med"); $diabetes_med_results = mysql_query($diabetes_med); $diabetesCount = mysql_num_rows($diabetes_med_results); while($diabetes_row = mysql_fetch_array($diabetes_med_results)){ // put items into an array ... maybe this helps.... $temp_array[] = $diabetes_row['dname']; } // Grab diabetes_meds and display items on first row. foreach($temp_array as $diabetes_drug){ $pain_meds_qry = mysql_query("select drug_name from pain_meds;"); // now lets do the pain_meds while($painmed_row = mysql_fetch_array($pain_meds_qry)) { <table> <tr id='record<?=++$increment?>'> <td> // Try printing the drug name on left-most column eg. Amaryl, Avandaryl...etc print $diabetes_drug; </td> <td> <input name="painmed[<?=$increment?>]" type="hidden" id="painmed<?=$increment?>" value="<?=$painmed_row['drug_name']?>"> <!-- print pain med eg. oxycode, Vicodin, ultram, morphine --> <?=$painmed_row['drug_name'] </td> <td><input type="text" name="effects[<?=$increment?>]" value="" size="3"> </td> </tr> </table> } } } At best this only generates one table regardless of how many diabetes_med are present. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ceci Posted March 31, 2010 Author Share Posted March 31, 2010 pls disregard this question. i think i resolved my own problem. thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.