SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    generate infinite textbox names and put in array

    depending on the query (usually date range), a undefined number of results will be shown on page

    there will be a text field next to each result, the textbox will be filled with a ID number by the user, which, when the user clicks submit should searched each entered number against a database

    the problem i am having is to be able to produce a unique textbox name, place it into an array(?) and then being able to put the values entered into the textboxes into variables

    current code looks like this:
    PHP Code:

    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
        echo 
    '<form name="findbatch" method="post" action="serialno.php">
        <table width="80%" align="center" border="0">
            <tr>
              <td width="60%">' 
    $row['stock_desc'] . '</td>
              <td width="20%><div align="center">' 
    $row['serial_no'] . '</div></td>
              <td width="20%><div align="center"><input type="text" size="15" name="batchno"></div></td>
            </tr>'
    ;

    echo 
    '<p><div align="center"><input type="submit" name="Submit" value="Submit"></form></div></p>';


    //at the top of the page:


    if (isset($_POST['submit'])) {

    $batchno[]=$_POST['batchno'];


    foreach (
    $batchno as $val) {

    echo 
    $val '<br>';


    current code is not working but its just to give you an idea

    cheers

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this perhaps?
    PHP Code:
    <?php
    echo '.....<input type="text" size="15" name="batchno['.$row['id'].']">';
    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would i be able to print the stored values when the user clicks submit?

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    /* the processing page */
    $batchno $_POST['batchno'];
    foreach(
    $batchno as $key => $value){
    print 
    "The id is " $key " and the value is " $value "<br />";
    }
    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers worked!
    much appreciated!

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need a little more help, i want to use each of the stored values in the array and use it to search a MYSQL database, producing an error if the value cannot be found in the database

    cheers

  7. #7
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see if this works for you:
    PHP Code:
    $batchno $_POST['batchno'];
    $errors 0;
    foreach(
    $batchno as $key => $value){
        
    $sql "SELECT * FROM table WHERE fieldname = " $value;
        
    $result mysql_query($sql);
        if(
    mysql_num_rows($result) == 0){
            
    $errors += 1;
        }
    }
    if(
    $errors 0){
        echo 
    "Some values were not found in the table.";


  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no its not working, it shows nothing when i run it,
    i also need to obtain the values of the ones that did work and didn't work, maybe in a variable

    did some testing

    PHP Code:

    require_once ('../mysql_connect.php');

    $batchno $_POST['batchno']; 
    $errors 0
    foreach(
    $batchno as $key => $value){ 

    echo 
    $value '<br>';
        
    $sql "SELECT * FROM batch WHERE batch_id = " $value
        
    $result mysql_query($sql); 
        echo 
    $result '<br>';
        if(
    mysql_num_rows($result) == 0){ 
            
    $errors += 1
        } 


    if(
    $errors 0){ 
        echo 
    "Some values were not found in the table."

    $value is correct but i get Resource id #5 , 6, 7, 8, 9, 10 for $result

  9. #9
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah but you're searching for the batch_id, so then...
    PHP Code:
    $sql "SELECT * FROM batch WHERE batch_id = " $key
    Don't bother echoing $result btw; it's used as the resource for any data you want to pull from the query.


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
  •