1337hovie
02-03-2010, 09:48 PM
ok what i have is my sql db is like this:
id,tier,src,school,startdate,enddate,allocation,generated,togoal,status,enrgoal,enrrate,notes,day[1-31].
I have code that prints that into a html table and it works GREAT.
BUT i need to remove the day1-31 from displaying. someone said to use an IF statement to not print those rows?
How do i do that?
(im not a coder, my lab partner was hit by a car and the rest of the group is picking up his slack, me being the most computer literate, got the coding job)
also, i need to remove the last two cells in the table which is (generated & allocation-total) they are useless. i just dont want to mess the code up.
'Generated' tab is in there twice, the one at the end..which i believe is in the code needs to be deleted, beacuse its already printing..look at my db layout at the top..its in the middle. the two cells at the end need to be removed.
but i need in the 'generated' & 'togoal' to have math involved.
day1+day2+day3+...day31; (day1-31) all added together to equal '$generated'. and subtract from 'allocation' to equal 'togoal'
this what i had before & it worked, but its on another page and not like updated to the DB..just calculated it on the page:
$day1 + $day2 + $day3 + $day4 + $day5 + $day6 + $day7 + $day8 + $day9 + $day10 + $day11 + $day12 + $day13 + $day14 + $day15 + $day16 + $day17 + $day18 + $day19 + $day20 + $day21 + $day22 + $day23 + $day24 + $day25 + $day26 + $day27 + $day28 + $day29 + $day30 + $day31 = $generated
$allocation - $generated = $togoal
so what i need is: the math to go into those two cells(generated & togoal) & to mask/hide print the days 1-31.
i belive the math is already in the code, but idk what im looking at. i just need those two cells to have that math. (generated & togoal are calucating)
$allocation is updated on db, and is user entereed.
THANKS
(my code):
//select all the data you need, sorted by tier and school
$sql = "SELECT * FROM schoolinfo ORDER BY tier, school";
$rs = mysql_query($sql);
//if $rs is false, we have an error. Unlikely (impossible, really) in this scenario, but get in the habit
if ( !$rs ) {
echo "Error executing query: {$sql}<P />Error returned: " . mysql_error();
die();
}
//initialize $previousTier to something
$previousTier = "";
//loop through the result set, assigning each new row to $row
while ( $row = mysql_fetch_assoc($rs) ) {
//if the tier of the current row is different than the tier we have already been on...
if ( $row['tier'] != $previousTier ) {
//if previousTier is not empty, close the previous table
if ( $previousTier != "" ) echo "</table>";
//set $previousTier to the current tier
$previousTier = $row['tier'];
//echo the current tier, and print the opening tags for a new table.
echo "<h3>{$row['tier']}</h3>";
echo "<table border=1 cellpadding=0>";
//print a header row
echo "<tr>";
//print the headers, using the KEYS of $row. Read the PHP manual page on arrays, and the manual page for array_keys
foreach ( array_keys($row) as $header ) {
echo "<th>{$header}</th>";
}
//we have two additional fields, total and allocation - total. Print the headers:
echo "<th>Generated</th><th>Allocation - Total</th>";
//close the header row
echo "</tr>";
}
//loop through $row and print out all the data:
echo "<tr>";
foreach ( $row as $field ) {
echo "<td>{$field}</td>";
}
}
//close the last table.
echo "</table>";
?>
like i said i am not a coder. if someone can frankenstein this together, that would be amazing. ive been googling and even rented books from library. but if someone can revise my code that would be amazing.
and my partner is ok, dude got hit by a car, so as good as he can get..lol.
recap:
1)need to output table from db, WITHOUT the days1-31.
2)need to remove the last two columns (generated & allocations-total) and add the math to the proper cells. (math is in there, just applied to wrong cells, i think..wrong cells = last two [labeld generated & allocations-total)
either rewrite script? or revise this one?
thanks so much really.
id,tier,src,school,startdate,enddate,allocation,generated,togoal,status,enrgoal,enrrate,notes,day[1-31].
I have code that prints that into a html table and it works GREAT.
BUT i need to remove the day1-31 from displaying. someone said to use an IF statement to not print those rows?
How do i do that?
(im not a coder, my lab partner was hit by a car and the rest of the group is picking up his slack, me being the most computer literate, got the coding job)
also, i need to remove the last two cells in the table which is (generated & allocation-total) they are useless. i just dont want to mess the code up.
'Generated' tab is in there twice, the one at the end..which i believe is in the code needs to be deleted, beacuse its already printing..look at my db layout at the top..its in the middle. the two cells at the end need to be removed.
but i need in the 'generated' & 'togoal' to have math involved.
day1+day2+day3+...day31; (day1-31) all added together to equal '$generated'. and subtract from 'allocation' to equal 'togoal'
this what i had before & it worked, but its on another page and not like updated to the DB..just calculated it on the page:
$day1 + $day2 + $day3 + $day4 + $day5 + $day6 + $day7 + $day8 + $day9 + $day10 + $day11 + $day12 + $day13 + $day14 + $day15 + $day16 + $day17 + $day18 + $day19 + $day20 + $day21 + $day22 + $day23 + $day24 + $day25 + $day26 + $day27 + $day28 + $day29 + $day30 + $day31 = $generated
$allocation - $generated = $togoal
so what i need is: the math to go into those two cells(generated & togoal) & to mask/hide print the days 1-31.
i belive the math is already in the code, but idk what im looking at. i just need those two cells to have that math. (generated & togoal are calucating)
$allocation is updated on db, and is user entereed.
THANKS
(my code):
//select all the data you need, sorted by tier and school
$sql = "SELECT * FROM schoolinfo ORDER BY tier, school";
$rs = mysql_query($sql);
//if $rs is false, we have an error. Unlikely (impossible, really) in this scenario, but get in the habit
if ( !$rs ) {
echo "Error executing query: {$sql}<P />Error returned: " . mysql_error();
die();
}
//initialize $previousTier to something
$previousTier = "";
//loop through the result set, assigning each new row to $row
while ( $row = mysql_fetch_assoc($rs) ) {
//if the tier of the current row is different than the tier we have already been on...
if ( $row['tier'] != $previousTier ) {
//if previousTier is not empty, close the previous table
if ( $previousTier != "" ) echo "</table>";
//set $previousTier to the current tier
$previousTier = $row['tier'];
//echo the current tier, and print the opening tags for a new table.
echo "<h3>{$row['tier']}</h3>";
echo "<table border=1 cellpadding=0>";
//print a header row
echo "<tr>";
//print the headers, using the KEYS of $row. Read the PHP manual page on arrays, and the manual page for array_keys
foreach ( array_keys($row) as $header ) {
echo "<th>{$header}</th>";
}
//we have two additional fields, total and allocation - total. Print the headers:
echo "<th>Generated</th><th>Allocation - Total</th>";
//close the header row
echo "</tr>";
}
//loop through $row and print out all the data:
echo "<tr>";
foreach ( $row as $field ) {
echo "<td>{$field}</td>";
}
}
//close the last table.
echo "</table>";
?>
like i said i am not a coder. if someone can frankenstein this together, that would be amazing. ive been googling and even rented books from library. but if someone can revise my code that would be amazing.
and my partner is ok, dude got hit by a car, so as good as he can get..lol.
recap:
1)need to output table from db, WITHOUT the days1-31.
2)need to remove the last two columns (generated & allocations-total) and add the math to the proper cells. (math is in there, just applied to wrong cells, i think..wrong cells = last two [labeld generated & allocations-total)
either rewrite script? or revise this one?
thanks so much really.