Jump to content

[SOLVED] Quiiiick question


tfburges

Recommended Posts

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

92648175vp5.png

 

"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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>
  ";
}

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.