0

good Day!, i have a question. I have the code below which return the value of pos_name and train_name from my DB. my question is how can i put the returned value inside the textbox in which each textbox has a unique name. cause i will going to save it to another db.

i want something like this

 <input type="text" name="<?php echo $row["pos_name"][0] ?>" value="<?php echo $row["train_name"][0] ?>"
 <input type="text" name="<?php echo $row["pos_name"][1] ?>" value="<?php echo $row["train_name"][1] ?>"
// The number of textbox will depend on the number of returned value or the ($i)



//MY PHP CODE =========
<?php 

    $con = mysql_connect("localhost","root","");
        if (!$con){
        die("Can not connect: " . mysql_error());
        }
        mysql_select_db("tms",$con);

 $Query="SELECT id,pos_name,train_name FROM pos_train_db ORDER BY id DESC LIMIT 15";
 $sql = mysql_query($Query, $con);

            $dyn_table = '<table border="1" cellpadding="10">';
           while( $row = mysql_fetch_array($sql)){

                $id = $row["id"];
                $pos_name = $row["pos_name"];
                $train_name = $row["train_name"];

                    if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")

            $dyn_table .= '<tr><td>' . $pos_name . '</td>';
        } else {
            $dyn_table .= '<td>' . $pos_name . '</td>';
        }
        $i++;
    }
    $dyn_table .= '</tr></table>';

            ?>    





       <?php 
//SOME TESTING CODE
               echo $dyn_table;

               echo $i;

               echo "<input type='text' value=" . "$pos_name" . ">";


                ?>

Please Help Thank you!

1
  • Is it the $row["pos_name"] at the top of your example or the $pos_name at the bottom that you are referring to? I mean in terms of which <input> you want modified? Commented Jan 9, 2015 at 6:20

1 Answer 1

1

Wasn't very clear as to what the OP was asking but -- I suppose this could be part of the answer:

<?php 

    $con = mysql_connect("localhost","root","");
        if (!$con){
        die("Can not connect: " . mysql_error());
        }
        mysql_select_db("tms",$con);

 $Query="SELECT id,pos_name,train_name FROM pos_train_db ORDER BY id DESC LIMIT 15";
 $sql = mysql_query($Query, $con);

            $dyn_table = '<table border="1" cellpadding="10">';
           while( $row = mysql_fetch_array($sql)){

                $id = html_entity_decode($row["id"]);
                $pos_name = html_entity_decode($row["pos_name"]);
                $train_name = html_entity_decode($row["train_name"]);
echo "<input type=\"text\" name=\"".$id."\" value=\"".$train_name."\"></input>";

                    if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")

            $dyn_table .= '<tr><td>' . $pos_name . '</td>';
        } else {
            $dyn_table .= '<td>' . $pos_name . '</td>';
        }
        $i++;
    }
    $dyn_table .= '</tr></table>';

            ?>    
Sign up to request clarification or add additional context in comments.

1 Comment

Wow thank you! yes this is what i needed $id = html_entity_decode($row["id"]); $pos_name = html_entity_decode($row["pos_name"]); $train_name = html_entity_decode($row["train_name"]); echo "<input type=\"text\" name=\"".$id."\" value=\"".$train_name."\"></input>"; im new you help me alot! thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.