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
https://forums.phpfreaks.com/topic/197119-creating-dynamic-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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