SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php and Input Boxes

    OK please excuse my ignorance.

    I have a dynamic text/input box, i make a call to the mysql database and for each line that is displayed i would like a text box. I would like the text box id to be the same as the id in the db so i can use it later (outside of the foreach loop) and the $value also displayed outside of the loop. I cant seem to get the id and the value matching up....

    Here is my code - please excuse the mess

    while ($row = mysql_fetch_array($query))
    {
    $pic = $row["picture_Url"];
    $price = $row["price"];
    $name = $row["name"];
    $id = $row["id"];

    $box_id = $id;

    echo "<input type=no_req name=no_req[] id=<?echo "$box_id" ?> >";

    echo "$box_id; *********Works here
    }

    echo "<br>";
    echo "<input type=\"submit\" name=\"Submit\" value=\"Update\" >";

    echo "<br>";

    foreach($no_req as $no_required) {
    echo "$no_required ";
    echo "$box_id<BR>\n"; *********This isnt working
    }


    I am submitting my form with:-
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">

    I suppose i want to create a new array from the results..

    Thank you for any guidance and please assume i am an idiot when you respond...

    I am banging my head against a wall

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo '<input type="text" name="no_req[]" value="'.$box_id.'" />'
    Is that what you meant?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    nearly there

    Thank you very much for your response Ian

    foreach($no_req as $no_required) {
    echo "$no_required ";
    echo "$box_id<BR>\n"; *********This isnt working
    }

    I sort of had something similar before, the problem is when i go through the foreach loop it displays the content of the text box each time but the $box_id displays the last value of the loop each time.

    eg;
    if the value of $no_required was 1 2 3

    and there were 3 text boxes

    it will display 1 3 2 3 3 3

    Sorry to bug you......... but WOO HOO i got a response, Thank you

  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by flissworld View Post
    I sort of had something similar before, the problem is when i go through the foreach loop it displays the content of the text box each time but the $box_id displays the last value of the loop each time.
    That's because $box_id is set before the loop and never changes inside it.

    What is the relation between $no_req and set of rows, fetched from the database? Are their sizes (counts of elements inside them) always equal values?

  5. #5
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorry i am so dumb

    Thanks Average Geek - I would like to think I am a practicing geek - but not doing a very good job in this instance!! jack of all trades, master of none as they say....

    Inside the for loop if i echo $box_id it displays correctly within the while loop but not the foreach loop afterwards.

    OK theoritically is very simple, and i still think it is but i am just NOT a programmer...... my brain isnt that way inclined

    I make a call to the database and select which records i need - i then need to put a text box next the entry and be able to associate the text box values with the records i have selected (like a multiple array containing the value entered by the user and the id of the record that came from the db) Thats why i thought if i could give the text box an array containing the values and use the $id of the selected records i can actually use the data that comes out as i want to do more calls to the database later.

    I only want the records to display if there has been an ebtry but thats another story.

    so $no_req = the value entered by the user and $id = the id of the record that the line/query/row that it is associated with the text box entry...

    Thanks in Advance

  6. #6
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Soooo

    i make a call to the db and bring back 3 rows of data

    records

    1, 3 and 9

    I then want a text box to appear next to each record.

    if i enter 1 then 5 and then 3 into each text box.

    I would like to use data from each record and multiply it by the values entered.

    i.e

    id value
    ------------
    1 x 1
    3 x 5
    9 x 3

    I need the id becasue i would then like more data from the db realating to the chosen entry.

    THANKS IN ADVANCE!!!

  7. #7
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Untested:
    PHP Code:
    $box_ids = array();
    while ($row = mysql_fetch_array($query)) 

      $pic = $row["picture_Url"]; 
      $price = $row["price"];
      $name = $row["name"];
      $id = $row["id"];

      $box_id = $id;
      $box_ids[] = $box_id;

      echo "<input type=no_req name=no_req[] id=<?echo "$box_id?> >";

      echo "$box_id;
    }

    echo "<br>";
    echo "<input type=\"submit\" name=\"Submit\" value=\"Update\" >";

    echo "<br>";

    foreach($no_req as $key = $no_required)
    {
      // Get box id with the same index as current "no required" has
      $box_id = $box_ids[$key];
      echo "$no_required ";
      echo "$box_id<BR>\n"; *********This isnt working
    }

  8. #8
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What is this mythical form input element of type "no_req"?
    Ian Anderson
    www.siteguru.co.uk

  9. #9
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no_req is the array that will allow me access the users input from the text boxes. The $box_id tells me which record the user input belongs to.

    (Apparantly, if it worked)

    I wish i could do this myself.....

    THANK YOU

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    My sarky post was trying to show you that there is no such form input element type as no_req. You can have any of the following at least, but not no_req ...

    text
    hidden
    radio
    checkbox
    submit
    reset
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorry.......

    Sorry Earl Grey its not working....

    I am only in Cyprus, maybe you could pop over and have a look?? LOL.

    I am going to read about Keys though until i can find a resolution, well, i ahve to resolve it - NO CHOICE.....

    ....and apologies for not getting back to you immediately - Duty called...

  12. #12
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I LIED!!!

    I LOVE YOU!!!!!!

    Sorry small TYPO:- foreach($no_req as $key => $no_required)

    THANKYOU very very very very very much


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •