0

Hello

I am using mysql with html to create a webpage

I have a table called people

This table has 2 fields, first_name and second_name

I have 5 records in this table

I want to select this information out of the MYSQL database and into fields on a form

These fields can then be overwitten with new values and sent back to the mysql database.... Can i select data into a field

ie <input value="from mysql" size=20 name="first_name" >

Thanks

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Rhyan
0

Hello

I am using mysql with html to create a webpage

I have a table called people

This table has 2 fields, first_name and second_name

I have 5 records in this table

I want to select this information out of the MYSQL database and into fields on a form

These fields can then be overwitten with new values and sent back to the mysql database.... Can i select data into a field

ie <input value="from mysql" size=20 name="first_name" >

Thanks

Hi there!
As far as I understand, you want to load values of first_name and second_name from your MySQL table into form fields.

Yes, you can do it, however you have to use a dynamic language like php or asp to run for you. If you're using PHP you can do it like this:

//connect to server
$dbconnect=mysql_connect('localhost', 'user', 'pass');
//select your database
$dbselect=mysql_select_db('database_name');
//set query parameter for your table
$query="SELECT first_name, last_name FROM names;";
//run the query into your SQL server
$run=mysql_query($query);
//get the number of rows your query has returned.
$rows=mysql_num_rows($run);

//make a simple cycle to run through all your returned records
echo '<table>';
//here is the cycle. note the way I made it, it will run as many times as the number of names have been returned from your databes. Instead of $rows, you can limit the cylce to any nymber. For example 5 times
for ($i=0; $i<$rows; $i++)
  {
    //loading returned values from database into an array
   $result=mysql_fetch_array($run);
    echo '<tr>
      <td><input name="first_name'.$i.'" value="'.$result['first_name'].'" /></td>
      <td><input name="last_name'.$i.'" value="'.$result['last_name'].'" /></td>
  </tr>';
//the cylce ends here
   }
echo '</table>';

That is all for loading your values into input elements.

Good luck

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.