Jump to content

creating dynamic tables


ceci

Recommended Posts

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.