displaying data to a table and calculate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidOwens
    New Member
    • Mar 2007
    • 56

    displaying data to a table and calculate

    hey guys i want to have a html form which users would fil in and they click display and it would be update to another form and calculations carried out

    e.g so just say they filled forms were it had

    name: , day worked mon,tues,weds,t hurs,fri: ,were worked: store, hosi(put number of hours worked in each),they then submit the form, the other form is then displayed and the total number of hours calculated

    ideas guys??
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Are you asking us to do your work for you? You need a HTML form and a script to do the calculations from the $_POST variables

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      David, First create your HTML Form to fetch the user inputs.

      embedded this elements in a form.

      [HTML]Name: <input type="text" name="name"/>
      Mon: <input type="text" name="day1"/>Hrs:<input type="text" name="hrs1"/>[/HTML]

      then from the PHP side. get this values entered by the user.

      [PHP]$name = $_POST['name'];
      $day1 = $_POST['day1'];
      $hrs1= $_POST['hrs1'];[/PHP]

      like wise get all the hours convert them to integer values then create a function to calculate them.

      from the same page you can print it back.

      if you don't have a idea to make it come with your HTML form Next time.

      Comment

      • DavidOwens
        New Member
        • Mar 2007
        • 56

        #4
        Originally posted by ajaxrand
        David, First create your HTML Form to fetch the user inputs.

        embedded this elements in a form.

        [HTML]Name: <input type="text" name="name"/>
        Mon: <input type="text" name="day1"/>Hrs:<input type="text" name="hrs1"/>[/HTML]

        then from the PHP side. get this values entered by the user.

        [PHP]$name = $_POST['name'];
        $day1 = $_POST['day1'];
        $hrs1= $_POST['hrs1'];[/PHP]

        like wise get all the hours convert them to integer values then create a function to calculate them.

        from the same page you can print it back.

        if you don't have a idea to make it come with your HTML form Next time.

        i have created a database table, in it it holds ID, Name, RegionID

        i now have a HTML page, its a table, one of the colums is name, i would like to auto populate the name column with data from the database, based on a regionid

        so say TESTER TEST is in region 5, i would like tester test to populate to the name coloumn in the region 5table.

        i know the query is something like

        SELECT * FROM users WHERE 'id = $id but im not quite sure.

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          this will work.
          Code:
          SELECT * FROM users WHERE id = '$id'

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Now you came up with database tables, first time its only a Application to calculate hours.

            if you want to store these things after calculating go and change your table structure.once you find out difficulties please come back with the codings.

            Comment

            • DavidOwens
              New Member
              • Mar 2007
              • 56

              #7
              Originally posted by ajaxrand
              Now you came up with database tables, first time its only a Application to calculate hours.

              if you want to store these things after calculating go and change your table structure.once you find out difficulties please come back with the codings.

              below is code for a test table i created, its just got the 1 colum, just to try and fill that from the databse table USERS.
              i would like it for when the page is loaded, then the name colum is already populated with a list of the names.

              not sure if you use the GET or POST METHOD?
              [php]
              <form action="haa_loc ation2.php" method="get">
              <body>
              <table width="7%" border="0" cellspacing="0" cellpadding="0" >
              <tr>
              <td><input name="id" type="text"></td>
              </tr>
              <tr>
              <td>&nbsp;</td>
              </tr>
              <tr>
              <td>&nbsp;</td>
              </table>
              </body>
              </html>


              here is the php.

              $sql=SELECT * FROM users WHERE id = '$id';

              //print $sql;
              if (!mysql_query($ sql,$con))
              {
              die('Error: ' . mysql_error());
              }
              echo "Records Added, Thank You";mysql_clos e($con)

              ?>
              [/php]
              whats confusing me is how does the table get auto populated in the id column when its loaded straight away,

              Read the Posting Guidelines before you post any further! Especially the part on how to enclose your code within php or code tags!!

              moderator
              Last edited by ronverdonk; Mar 25 '07, 12:13 PM. Reason: warning and adding tags

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

                Comment

                • DavidOwens
                  New Member
                  • Mar 2007
                  • 56

                  #9
                  [php]
                  $con = mysql_connect(" localhost","roo t","password ");
                  if (!$con)
                  {
                  die('Could not connect: ' . mysql_error());
                  }

                  mysql_select_db ("dohc_intra ", $con);

                  $result = mysql_query("SE LECT id, staffid, region, firstname, surname FROM users WHERE region='Do'");
                  echo "<table border='1'>
                  <tr>
                  <th>ID</th>
                  <th>Region ID</th>
                  <th>Staffid</th>
                  <th>Firstname </th>
                  <th>Saturday</th>
                  <th>Monday</th>
                  <th>Tuesday</th>
                  <th>Wednesday </th>
                  <th>Thursday</th>
                  <th>Friday</th>
                  <th>Default</th>
                  </tr>";while($ro w = mysql_fetch_arr ay($result))
                  {
                  echo "<tr>";
                  echo "<td>" . $row['id'] . "</td>";
                  echo "<td>" . $row['region'] . "</td>";
                  echo "<td>" . $row['staffid'] . "</td>";
                  echo "<td>" . $row['firstname'] . "</td>";
                  echo "<td>" . $row['surname'] . "</td>";
                  //select
                  //query
                  //while {
                  echo
                  // }
                  // close select
                  echo "</tr>";
                  }
                  echo "</table>";mysql_c lose($con);
                  ?>
                  </body>
                  </html>
                  [/php]
                  i have got the code to work :), i do need to change the THREAD title because i dont need to calculate no more, but dont want to create another thread while i could just continue this.

                  my next problem is where the commented sections are in the space above, i want to have a drop down list with a list of locations, as you can see iv tried to comment how i think the code layput should be, but im just not sure how to auto extract the data from a databse and be able to show it as a drop down in PHP.

                  so on the php table form, they would have day of week, with a drop down list of locations

                  in the database, those locations would be stored under the day of week for that user.
                  Last edited by ronverdonk; Mar 23 '07, 01:24 PM. Reason: enclose code within tags

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    Why is it so difficult to comply with the Posting Guidelines and enclose your code within tags!! You were asked nicely but I will not ask again.

                    moderator

                    Comment

                    • DavidOwens
                      New Member
                      • Mar 2007
                      • 56

                      #11
                      Originally posted by ronverdonk
                      Why is it so difficult to comply with the Posting Guidelines and enclose your code within tags!! You were asked nicely but I will not ask again.

                      moderator
                      sorry, will do on next posting of code. thanks.

                      the above code will be ok for now though ye???

                      Comment

                      • ak1dnar
                        Recognized Expert Top Contributor
                        • Jan 2007
                        • 1584

                        #12
                        Dynamic List menu

                        [PHP]<?php
                        require '../db.php';// Connection String File
                        $namequery = "SELECT p_name FROM products";

                        $result = mysql_query($na mequery) or die('Error, query failed');
                        $count = mysql_num_rows( $result);
                        if ($count > 0)
                        {

                        echo '<select name="item">';
                        while($result_r ow = mysql_fetch_arr ay($result))
                        {
                        echo '<option value="'.$resul t_row[1].'" >';
                        echo ($result_row[0]);
                        echo '</option>';
                        }
                        echo '</select>';
                        }
                        else
                        {
                        echo "There are no project numbers in the system";
                        }
                        ?>[/PHP]

                        Comment

                        • DavidOwens
                          New Member
                          • Mar 2007
                          • 56

                          #13
                          Originally posted by ajaxrand
                          Dynamic List menu

                          [PHP]<?php
                          require '../db.php';// Connection String File
                          $namequery = "SELECT p_name FROM products";

                          $result = mysql_query($na mequery) or die('Error, query failed');
                          $count = mysql_num_rows( $result);
                          if ($count > 0)
                          {

                          echo '<select name="item">';
                          while($result_r ow = mysql_fetch_arr ay($result))
                          {
                          echo '<option value="'.$resul t_row[1].'" >';
                          echo ($result_row[0]);
                          echo '</option>';
                          }
                          echo '</select>';
                          }
                          else
                          {
                          echo "There are no project numbers in the system";
                          }
                          ?>[/PHP]
                          [PHP]<?php
                          $con = mysql_connect(" localhost","roo t","password ");
                          if (!$con)
                          {
                          die('Could not connect: ' . mysql_error());
                          }

                          mysql_select_db ("db_name", $con);




                          $result = mysql_query("SE LECT id, staffid, region, firstname, surname FROM users WHERE region='Pm'");

                          echo "<table border='1'>
                          <tr>
                          <th>ID</th>
                          <th>Region ID</th>
                          <th>Staffid</th>
                          <th>Firstname </th>
                          <th>Surname</th>
                          <th>Saturday</th>
                          <th>Monday</th>
                          <th>Tuesday</th>
                          <th>Wednesday </th>
                          <th>Thursday</th>
                          <th>Friday</th>
                          <th>Default</th>



                          </tr>";while($ro w = mysql_fetch_arr ay($result))
                          {
                          echo "<tr>";
                          echo "<td>" . $row['id'] . "</td>";
                          echo "<td>" . $row['region'] . "</td>";
                          echo "<td>" . $row['staffid'] . "</td>";
                          echo "<td>" . $row['firstname'] . "</td>";
                          echo "<td>" . $row['surname'] . "</td>";


                          $namequery = "SELECT name FROM stores";

                          $result = mysql_query($na mequery) or die('Error, query failed');
                          $count = mysql_num_rows( $result);
                          if ($count > 0)
                          {

                          echo '<select name="saturday" >';
                          while($result_r ow = mysql_fetch_arr ay($result))
                          {
                          echo '<option value="'.$resul t_row[1].'" >';
                          echo ($result_row[0]);
                          echo ($result_row[0]);
                          echo '</option>';
                          }
                          echo '</select>';
                          }
                          else
                          {
                          echo "no store in records";
                          }








                          echo "</tr>";

                          }
                          echo "</table>";mysql_c lose($con);
                          ?> [/PHP]

                          </body>
                          </html>

                          the above enters the drop down into the table, but in the wrong location , i would like it to put the drop down in the location under the saturday column and the mon,tues,weds,t hurs,fri etc.

                          thanks guys.

                          Comment

                          • ak1dnar
                            Recognized Expert Top Contributor
                            • Jan 2007
                            • 1584

                            #14
                            Should we create your HTML headings also. But not me.
                            http://www.w3schools.com/php/php_mysql_select.asp Try to learn it by your self.

                            Comment

                            • DavidOwens
                              New Member
                              • Mar 2007
                              • 56

                              #15
                              Originally posted by ajaxrand
                              Should we create your HTML headings also. But not me.
                              http://www.w3schools.com/php/php_mysql_select.asp Try to learn it by your self.
                              i just asked a question, i dont want you to do it for me, i would just like some pointed, because im just not that good with php.

                              so please would you help me.

                              even when i look through the tutorials, i still casn get the drop down to go into the saturday column, been spending the past 3hrs trying to do it.

                              so please help.

                              the only thing i can think of is that sat-fri is not in the database, but i just want the users to be able to pick the locations were they have been or will be on those days....so dont think there is a need for them to be in database, just put the drop downlist in that days colum.

                              Comment

                              Working...