View Single Post
Old 10-27-2004, 02:04 PM   #1 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 167
DavH27 is on a distinguished road
EMERGENCY: Dynamic form processing

AAAAAAAAAAAAAAAAAAAAAGHHHH!!!

I'm currently suffering from not carefully making sure a client knew what they wanted before bidding on this job.

He is a 'website reviewer guy' who offers a free website evaluation service. Client email him and he fills in my 'review form'. There will be about 25-35 form 'components'.

Each 'component' will have a title, a fixed paragraph, a choice of 1-5 star rating and an optional comment box.

The 'thankyou.php' page should take these inputs and save them to a database.

Not a problem for me...except he won't tell me how many of the 'components' I will be coding in!!

This means setting up a 'base set' components of about 10 components.

I done this in a db OK. The review form page should then loop the form's code for each component and dynamically pull them from the db to allow him to fill in the data.

The table 'components' has below columns:
cID (auto inc)
headertxt - this is used in the review form and elsewhere
fixedtxt - this will be used on the client's page when they view thier review form results by pulling it 'dynamically' *cringe* from the db. I won't be covering this yet this should be simple.

I've done the form 'pulling' like this:
PHP Code:
    $i 1//sets the counter
    
$sql mysql_query("SELECT * FROM components"); // this is where those 'components' reside.

    
while ($row mysql_fetch_array($sql))
    {
    echo 
"<tr> 
      <td colspan='2'><BR /><b>"
.$row['headertxt']."</b></td>
    </tr>
    <tr> 
      <td class='bottomborder' colspan='2'> 
        <input type='radio' name='q"
.$i."_star' value='1' class='formborder'>
        1 
        <input type='radio' name='q"
.$i."_star' value='2' class='formborder'>
        2 
        <input type='radio' name='q"
.$i."_star' value='3' class='formborder'>
        3 
        <input type='radio' name='q"
.$i."_star' value='4' class='formborder'>
        4 
        <input type='radio' name='q"
.$i."_star' value='5' class='formborder'>
        5 out of 5</td> // these are radios for the rating
    <tr>
      <td colspan='2' height='22'>
      Offer own service / further action<br />
        <textarea name='recAction"
.$i."' cols='90' class='formborder'></textarea>
      </td>
    <tr> 
      <td colspan='2' height='22' class='bottomBorder'>
      Further comments <font size='-1'>(optional)</font><BR />
        <textarea name='comments"
.$i."' cols='90' class='formborder'></textarea>
      </td>"
;
     
$i++; // increments loops number so every time, the variable is plus one until
          // while condition is false. 
        
// end while loop 
This code displays the form on review.php with dynamic numbering for the elements every time a new component is 'pulled'.

This way, if he was to add a 'component' to the db, it would be called in this page.


The next part is the bit that is doing my head in. For testing I am just trying to ECHO the data used to store to db. If you cna help me then that is all I would like you to do for me is ECHO the results.

What I need to do is loop through each component and echo the returned value. I have tried to think of a solution but I haven't even got that far!

EDIT:To start with I initially thought using a variable inside another variable was God's solution to hellish programming head ferks:
PHP Code:
$count 1
while ($count <= $total_rows)
{
echo 
$_POST['q$count_star'];
$count++

But this obviously isn't possible, so how can I loop through the q1_star, q2_star, etc?

I thought of maybe going through the $_POST[''] array and assigning the value to an increasing variable. After every loop the variable NAME would increment so the next time it would be empty for a new value. But thinking about it now it isn't possible...SH*T!!!

Please help me oh grand masters of CodeNewbie

Great overhaul btw...me likey very much!!

EDIT2: To anyone, if you think it would be easier to DO it rather then explain it then I Can provide all code through email or MSN.

My deadline is 3 days and I'm brickin it all cus this stupid b4st4rd won't tell me how many 'component's I need to code in. If I knew the amount then the cosding would be a piece of cake with next to no loops needed.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a

Last edited by DavH27; 10-27-2004 at 02:25 PM. Reason: Adding new info / the code I thought worked
DavH27 is offline   Reply With Quote