Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 5th, 2003, 01:08 PM
dmonk dmonk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 22 dmonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP: create tables w/ loop & iterate functions ?

I'm trying to get the concept of the loop down. I'm creating a crude budget tool where I can compare expenses to income.

1. I need to create table rows with a loop
2. need to have a loop check if the value is_numeric (if not echo "value ! num"
2. need to have a loop add the values for each "amount" entered to get a "Total".

I've been able to create the table rows. I haven't figured out how to get the loop to add the money values entered under "amount".

My other problem (of lesser priority) is that the values submitted and displayed change once I submit the form (to itself).

Usually the fields get filled with the first value entered on the first row. i.e. if ammount val 100 entered on first row and val 30 entered on second row, the total is 130 BUT the number displayed are (for each row instance) "100"The numbers are supossed to remain there once the form reloads.

Those are the main tasks. I know that there has to be a way to loop the entire task. I'm just not entirely sure on how to apply the loop tool for all these instances at for each iteration.

Any tips would be greatly appreciated.

Thank you.

DM


--------------

PHP Code:
<?php

//APPLICATION HELPS TO FIGURE OUT EXPENSE VS. INCOME
//THE LOOP TO CREATE THE TABLE ROWS
//TWO COLUMNS ONE IS SOURCE THE OTHER AMOUNT
//THE FORM IS POSTED TO ITSELF

for ($i 1$i 3$i++)
{
  
$source_name 'source'."$i";    
  
$source_value =$HTTP_POST_VARS['source1'];

  
$amount_name 'amount'."$i";
  
$amount_value =$HTTP_POST_VARS['amount1'];

//SECOND TABLE ROW
  
$amount_value2 $HTTP_POST_VARS['amount2'];

//ADDING THE ROW VALUES TO GET TOTAL INCOME
    
$inc_total = ($amount_value $amount_value2);


//.HTML. CODE FOR TABLE

  
print '<tr>';
  print 
"<td>";
  print 
"<input type=text name=$source_name value='$source_value'>";
  print 
"</td>";

  print 
"<td>";
  print 
"<input type=text name=$amount_name value='$amount_value'>";

  print 
"</td>";


//CHECKING IF AMOUNT ENTERED IS NUMERIC (ROW 1), IF NOT ERROR MESG
             
$amount_value =$_GET['amount1'];

             if (
is_numeric($amount_value))
             {
                echo 
" ";

            }else
            {
                  print 
"<td>";
                  print 
"<font color=red size=-5>Not numeric!</font>";
                  print 
"</td>";
                  print 
'</tr>';
             }
}

//CHECKING IF AMOUNT ENTERED IS NUMERIC (ROW 2), IF NOT ERROR MESG
             
$amount_value2 $_GET['amount2'];

             if (
is_numeric($amount_value))
             {
                echo 
" ";

            }else
            {
                  print 
"<td>";
                  print 
"<font color=red size=-5>Not numeric!</font>";
                  print 
"</td>";
                  print 
'</tr>';
             }

?>

Reply With Quote
  #2  
Old July 6th, 2003, 10:41 AM
SilkySmooth's Avatar
SilkySmooth SilkySmooth is offline
Newbie :P
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2001
Location: In the PHP Engine :-)
Posts: 2,880 SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 32 m 23 sec
Reputation Power: 15
I am assuming you have answered your questions due to your newer posting in the PHP Forum?
__________________
---------------------
-- SilkySmooth --
---------------------
Proxy | Little Directory

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > PHP: create tables w/ loop & iterate functions ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway