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

Member Avatar for Rhyan

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.