tfburges Posted July 7, 2008 Share Posted July 7, 2008 I'm having some trouble figuring out how to get this to work correctly. It shouldn't hard at all for you pros out there. I could figure it out with enough time/research but I'm growing more and more impatient, it seems, because I know how simple it is yet finding the right syntax takes forever. An experienced human brain is probably the quickest solution. $q1 = "SELECT DISTINCT `section_name` FROM `reports` WHERE `report_name` = '$selected_report' AND `section_name` NOT IN ('Machine Info.','Machine Information','Machine Info','Customer Info.','Customer Information','Customer Info')"; $q2 = "SELECT `field_desc`, `field_desc_i`, `field_type`, `field_length`, `unit_type` FROM `reports` WHERE `report_name` = '$selected_report' AND `section_name` NOT IN ('Machine Info.','Machine Information','Machine Info','Customer Info.','Customer Information','Customer Info')"; if ( ($r1 = mysql_query( $q1, $link )) === FALSE ) exit( 'Query1 failed' ); if ( ($r2 = mysql_query( $q2, $link )) === FALSE ) exit( 'Query2 failed' ); while ( $data1 = mysql_fetch_assoc( $r1 ) ) { echo " <tr><td colspan=2 align=center><h3>",$data1['section_name'],"</h3></td></tr> "; while ( $data2 = mysql_fetch_assoc( $r2 ) ) { echo " <tr><td width=230 align=right valign=middle>",$data2['field_desc'],": </td><td width=230 align=left valign=middle><input name=\"",$data2['field_desc_i'],"\" type=",$data2['field_type']," maxlength=",$data2['field_length'],"> ",$data2['unit_type']," <input type=checkbox name=noneatm value=1></td></tr> "; } echo " <tr><td colspan=2> </td></tr> <tr><td colspan=2> </td></tr> <tr><td colspan=2> </td></tr> "; } Yields... "Inlet Air Temperature" is supposed be under "Measurements." My first guess was to turn... while ( $data2 = mysql_fetch_assoc( $r2 ) ) { ...into something like... while ( $data2 = mysql_fetch_assoc( $r2 ) && ???? ) { I've tried a few different things but I guess I just can't wrap my mind around it. Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 7, 2008 Share Posted July 7, 2008 what exactly are you trying to do? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 7, 2008 Share Posted July 7, 2008 I think Inlet Air Temperature is getting returned in your first query, which is why it is in the first category. You probably have to make sure your query is getting what you want it to. Quote Link to comment Share on other sites More sharing options...
tfburges Posted July 7, 2008 Author Share Posted July 7, 2008 what exactly are you trying to do? I'm building a form generator from a parent form where the sections and underlying fields are displayed in a certain format, i.e. similar to the ss in my first post. In the database/table, the fields are linked to the section names. +--------------------------+----------------+--------+------------+-------------+-----------------------+-----------------------+------------+--------------+-----------+----------+ | report_name | section_name | preset | add_preset | preset_name | field_desc | field_desc_i | field_type | field_length | unit_type | required | +--------------------------+----------------+--------+------------+-------------+-----------------------+-----------------------+------------+--------------+-----------+----------+ | Air Dryer Operator's Log | Machine Info. | none | 0 | | Dryer Serial No. | dryer_serial_no | text | 10 | | 1 | | Air Dryer Operator's Log | Machine Info. | none | 0 | | Dryer Model No. | dryer_model_no | text | 10 | | 1 | | Air Dryer Operator's Log | Customer Info. | none | 0 | | Company Name | company_name | text | 20 | | 1 | | Air Dryer Operator's Log | Ratings | none | 0 | | Amps | amps | text | 6 | | 0 | | Air Dryer Operator's Log | Ratings | none | 0 | | Replacement Element | replacement_element | text | 15 | | 0 | | Air Dryer Operator's Log | Measurements | none | 0 | | Inlet Air Temperature | inlet_air_temperature | text | 6 | | 0 | +--------------------------+----------------+--------+------------+-------------+-----------------------+-----------------------+------------+--------------+-----------+----------+ The fields should be under their respective sections. Quote Link to comment Share on other sites More sharing options...
tfburges Posted July 7, 2008 Author Share Posted July 7, 2008 I took a short break from it and worked on some other stuff for a bit, and I got it to work when I came back to it. This is the solution: $q1 = "SELECT DISTINCT `section_name` FROM `reports` WHERE `report_name` = '$selected_report' AND `section_name` NOT IN ('Machine Info.','Machine Information','Machine Info','Customer Info.','Customer Information','Customer Info')"; if ( ($r1 = mysql_query( $q1, $link )) === FALSE ) exit( 'Query1 failed' ); while ( $data1 = mysql_fetch_assoc( $r1 ) ) { $sect_name = $data1['section_name']; echo " <tr><td colspan=2 align=center><h3>",$sect_name,"</h3></td></tr> "; $q2 = "SELECT `field_desc`, `field_desc_i`, `field_type`, `field_length`, `unit_type` FROM `reports` WHERE `report_name` = '$selected_report' AND `section_name` = '$sect_name'"; if ( ($r2 = mysql_query( $q2, $link )) === FALSE ) exit( 'Query2 failed' ); while ( $data2 = mysql_fetch_assoc( $r2 ) ) { echo " <tr><td width=230 align=right valign=middle>",$data2['field_desc'],": </td><td width=230 align=left valign=middle><input name=\"",$data2['field_desc_i'],"\" type=",$data2['field_type']," maxlength=",$data2['field_length'],"> ",$data2['unit_type']," <input type=checkbox name=noneatm value=1></td></tr> "; } echo " <tr><td colspan=2> </td></tr> <tr><td colspan=2> </td></tr> <tr><td colspan=2> </td></tr> "; } 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.