473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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,thurs,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??
Mar 21 '07 #1
28 4325
code green
1,726 Expert 1GB
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
Mar 22 '07 #2
ak1dnar
1,584 Expert 1GB
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.
Mar 22 '07 #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.

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.
Mar 22 '07 #4
ak1dnar
1,584 Expert 1GB
this will work.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM users WHERE id = '$id' 
Mar 23 '07 #5
ak1dnar
1,584 Expert 1GB
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.
Mar 23 '07 #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.

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_location2.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_close($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
Mar 23 '07 #7
[php]
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("dohc_intra", $con);

$result = mysql_query("SELECT 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($row = mysql_fetch_array($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_close($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.
Mar 23 '07 #9
ronverdonk
4,258 Expert 4TB
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
Mar 23 '07 #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
sorry, will do on next posting of code. thanks.

the above code will be ok for now though ye???
Mar 23 '07 #11
ak1dnar
1,584 Expert 1GB
Dynamic List menu

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

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

echo '<select name="item">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_row[1].'" >';
echo ($result_row[0]);
echo '</option>';
}
echo '</select>';
}
else
{
echo "There are no project numbers in the system";
}
?>[/PHP]
Mar 26 '07 #12
Dynamic List menu

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

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

echo '<select name="item">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_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","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db_name", $con);




$result = mysql_query("SELECT 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($row = mysql_fetch_array($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($namequery) or die('Error, query failed');
$count = mysql_num_rows($result);
if ($count > 0)
{

echo '<select name="saturday">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_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_close($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,thurs,fri etc.

thanks guys.
Mar 26 '07 #13
ak1dnar
1,584 Expert 1GB
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.
Mar 26 '07 #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.
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.
Mar 26 '07 #15
ak1dnar
1,584 Expert 1GB
Please post your mySQL script here.
Mar 26 '07 #16
Please post your mySQL script here.

not sure if this is what you mean

[php]
$result = mysql_query("SELECT staffid, region, firstname, surname FROM users WHERE region='Pm'");

echo "<table border='1'>
<tr>
<th>Region ID</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($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['region'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";

$namequery = "SELECT region_id, name FROM stores WHERE region_id='REGION5'order by name ASC";

$result = mysql_query($namequery) or die('Error, query failed');
$count = mysql_num_rows($result);
if ($count > 0)
{
echo '<select name="item">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_row[0].'" >';
echo ($result_row[1]);

echo '</option>';
}
echo '</select>';
[/php]

so the above code, prints out the ID, firstname, surname etc from users where the region id is PM, then comes the drop down list, which does what i want, but just cant get it in the right place....and you know when u think about a problem to much ,u get the old headache and just cant think, that what i have got now.

pass me the vodka lol.
Mar 26 '07 #17
ak1dnar
1,584 Expert 1GB
I asked about the mySQL script that you used to create the table.
if it is not available export it. from PhpMyadmin. and post it here
Mar 26 '07 #18
I asked about the mySQL script that you used to create the table.
if it is not available export it. from PhpMyadmin. and post it here
-- Table "stores" DDL

CREATE TABLE `stores` (
`id` int(4) NOT NULL auto_increment,
`store_id` varchar(250) default NULL,
`name` varchar(250) default NULL,
`store_type_id` varchar(250) default NULL,
`region_id` varchar(250) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



-- Table "users" DDL

CREATE TABLE `users` (
`id` int(10) NOT NULL auto_increment,
`region` varchar(250) default NULL,
`staffid` varchar(250) default NULL,
`firstname` varchar(250) default NULL,
`surname` varchar(250) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Mar 26 '07 #19
-- Table "stores" DDL

CREATE TABLE `stores` (
`id` int(4) NOT NULL auto_increment,
`store_id` varchar(250) default NULL,
`name` varchar(250) default NULL,
`store_type_id` varchar(250) default NULL,
`region_id` varchar(250) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



-- Table "users" DDL

CREATE TABLE `users` (
`id` int(10) NOT NULL auto_increment,
`region` varchar(250) default NULL,
`staffid` varchar(250) default NULL,
`firstname` varchar(250) default NULL,
`surname` varchar(250) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


please guys...iv been searchin this problem for the past 2hrs and still nothing, lol looked through most of the documentation on the subject on this site.

if u look at the php code few posts up, you can see that i have a drop down and its currently displaying stores which match a certain region ID, but the drop down is displayin in the wrong place and i dont know how to get it in place, under the heading SATURDAY in the display tabel:(, once thats done my problem is sorted, PLEASE PLEASE guys, check out the code, and put it right, it not like i havent tried to sort the problem out, startin to get depressed now, cuz iv been searchin and looked through countless webpages and still nuffin.

please help.
Mar 26 '07 #20
ak1dnar
1,584 Expert 1GB
Try to do the same to remaining days also by using this way.
[PHP]
<?php
$con = mysql_connect("localhost","root","dba");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);

$sql="SELECT id, staffid, region, firstname, surname FROM users WHERE region='region1'";
$result=mysql_query($sql) or die("Error Occured while Searching Records : " . mysql_error());

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($row = mysql_fetch_assoc($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($namequery) or die('Error, query failed');

echo '<td><select name="saturday">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_row[0].'" >';
echo ($result_row[0]);
echo '</option>';
}
echo '</select></td>';

echo "</tr>";
}
echo "</table>";mysql_close($con);
?>

[/PHP]
Mar 27 '07 #21
Try to do the same to remaining days also by using this way.
[PHP]
<?php
$con = mysql_connect("localhost","root","dba");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);

$sql="SELECT id, staffid, region, firstname, surname FROM users WHERE region='region1'";
$result=mysql_query($sql) or die("Error Occured while Searching Records : " . mysql_error());

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($row = mysql_fetch_assoc($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($namequery) or die('Error, query failed');

echo '<td><select name="saturday">';
while($result_row = mysql_fetch_array($result))
{
echo '<option value="'.$result_row[0].'" >';
echo ($result_row[0]);
echo '</option>';
}
echo '</select></td>';

echo "</tr>";
}
echo "</table>";mysql_close($con);
?>

[/PHP]

thanks mate, go that to work, lol all that time spent yesterday n its almost sorted in the space of a page view. you guys do a fantastic job, keep up the good work.
Mar 27 '07 #22
ak1dnar
1,584 Expert 1GB
Its a pleasure to hear that. ;)
Mar 27 '07 #23
Its a pleasure to hear that. ;)
kist noticed one last problem, is that its only displaying 1 record, but i would like it to display all the record that the query is asking.

so for example, if i was to query by region4, it should display 25 records, not just the one.

but im going to try sort this out on my own, ul hear back from me later, if iv had no success.

cheers guys.

ps. do you know were the problem lies???
Mar 27 '07 #24
kist noticed one last problem, is that its only displaying 1 record, but i would like it to display all the record that the query is asking.

so for example, if i was to query by region4, it should display 25 records, not just the one.

but im going to try sort this out on my own, ul hear back from me later, if iv had no success.

cheers guys.

ps. do you know were the problem lies???

well guys its take this long and havent manageed to sort it :(, lol we are talkin a good 4hrs after i have done other things, oh da joys.

lol reaches for the orange juice(wishin it ws vodka).
Mar 27 '07 #25
kist noticed one last problem, is that its only displaying 1 record, but i would like it to display all the record that the query is asking.

so for example, if i was to query by region4, it should display 25 records, not just the one.

but im going to try sort this out on my own, ul hear back from me later, if iv had no success.

cheers guys.

ps. do you know were the problem lies???

well guys its take this long and havent manageed to sort it :(, lol we are talkin a good 4hrs after i have done other things, oh da joys.

lol reaches for the orange juice(wishin it ws vodka).
Mar 27 '07 #26
ronverdonk
4,258 Expert 4TB
The reason that it displays only 1 dropdown box in your code is that you use the $result variable, holding the resource ID of the query, in both queries, destroying the result from the first query. I have changed the resource ID variable of the second query to $result1, as you see in the following sample.

Also, but that will get you into problems later, you use the fixed name 'saturday' for all <select> drop down boxes. When posting the data you will only find one $_POST['saturday'] so you have to make that select name different for each box. I suggest adding an index to it, so they will be unique.

Also, in the following code snippet I added the create and inserts of both tables as a comment. I used that in my test. Good luck.

[php]
<?php
/*
create table users (id int, staffid int, region varchar(20), firstname varchar(20), surname varchar(20));
insert into users values(1,1,'region1','John', 'Doe'),(2,2,'region1','Pete', 'Mackay');
create table stores (name varchar(10));
insert into stores values('Name1'),('Name2'),('Name3'),('Name4'),('Na me5'),('Name6');
*/
$con = mysql_connect("localhost","ronverdonk","ronnie09") ;
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("vwso", $con);

$sql="SELECT id, staffid, region, firstname, surname FROM users WHERE region='region1'";
$result=mysql_query($sql)
or die("Error Occured while Searching Records : " . mysql_error());
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($row = mysql_fetch_assoc($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 ";
$result1 = mysql_query($namequery)
or die('Error, query failed');

echo '<td><select name="saturday">';
while($result_row = mysql_fetch_array($result1)) {
echo '<option value="'.$result_row[0].'" >';
echo ($result_row[0]);
echo '</option>';
}
echo '</select></td>';
echo "</tr>";
}
echo "</table>";mysql_close($con);
?>[/php]

Ronald :cool:
Mar 27 '07 #27
ak1dnar
1,584 Expert 1GB
I really missed that Ronald, sorry its my mistake.
Mar 28 '07 #28
ronverdonk
4,258 Expert 4TB
No problem, can happen (and will happen one day) to anyone.

Ronald :cool:
Mar 28 '07 #29

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: I_love_php | last post by:
Here is the problem I create an prediction system for NBA games the idea is any of my users can come and predcit for the game (who will win and what is the scores ) and everytime one of...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
2
by: marvin | last post by:
Hi, I am trying to display images in a repeater from a SQL database and do some transformations on the image prior to displaying them (such as thumbnail with a shadow). The problem is I can't...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
2
by: Fedor G via DotNetMonster.com | last post by:
Pls help me manage the data displaying on the webform aspx c# page. I used Dreamweaver to manage data displaying in the repeat table, ie simply dragged the fields to the table cells, where I need...
0
by: latin & geek via DotNetMonster.com | last post by:
hi! ok, im working on a database application. ive successfully managed to establish a relationship between two tables and display them on a datagrid, edit and add new records to them. now i...
2
by: rfmatthews | last post by:
I am not familiar with programming languages. I use Access because it is simple to construct queries. PROBLEM: In a database used to calculate employee payslips everything went smoothly on both...
9
by: Cogito | last post by:
My program builds several tables using inner HTML. All the tables are displayed only when the program terminates. How can I make it display one table at a time and then wait for a click before...
11
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>">...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.