SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    0 Post(s)
    0 Thread(s)

    Percentage in mysql query

    Okay, so I am a newbie to php and mysql. I will try to explain what I am trying to accomplish as best I can. I have a table with the following fields: wireGauge, time, fracture and other fields not used in this query. The fracture field stores the fracture point each time a record is added. There are 3 types of fracture points: anchor bend, break back and weld. What I am trying to do is figure out the percentage for each fracture point for a given wireGauge (such as 3, there are 4 different wireGauges: 2, 3, 4 and 4.5). I also want the user to be able to select the range of time from which to generate this report. So if there are 20 records I want to write a query that figures out the percentage of anchor bends, the percentage of break backs and the percentage of welds between a chosen time period for a given wireGauge such as 3. Once I have written the query I also need to figure out how to display the percentages in a table using php.

    I have attached a screenshot of my table.

    So far I have written the following:
    PHP Code:
    $sql="SELECT fracture, COUNT(*)
    FROM welded_wire_ties
    WHERE time between '
    $time1' and '$time2'
    AND wireGauge = '3'
    GROUP BY fracture"
    $result mysql_query($sql$conn) or trigger_error("SQL"E_USER_ERROR);
    $row mysql_fetch_assoc($result)) 

    $bbcount0 $row['fracture'];
    $bbcount1 $row['fracture'];
    $bbcount2 $row['fracture'];

    To print the percentages later on the page I have the following inside a table:
    HTML Code:
                     <?php echo "$bbcount1"; ?>
                     <?php echo "$bbcount0"; ?>
                     <?php echo "$bbcount2"; ?>
    Thanks for any help to understand and solve this.
    Attached Images Attached Images


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts