Jump to content

Data to Text Area


zenix

Recommended Posts

Hello, I am trying to learn php and mysql, and making pretty good progress. I've developed a database for a make believe company and have it working correctly. I thought it'd be neat to have the data (such as last name, first name and phone) appear in a text area at the top or bottom of the form that I use to enter/modify and view my data. I'd like to make it so I can click on an entry in the text area and have the fields of the form populate with the relevant data.

 

Someone mentioned I should use a drop down. I've tried this, I get the info into the drop down alright, but don't know how to go about making the data clickable so the info. fills out the form on the page. I think I'd really prefer a scrolling text area though, but when I try THIS approach I keep getting an error stating that the ...mysql_fetch_array ($result) is not a valid MySQL entry.

 

If someone could help me out, I'd really appreciate it. I've learned a lot this year, apparently I have quite a ways to go.

 

Here is the code I have for the drop down.

 

<?php

include("connect.php");

$result = mysql_query("SELECT lname, fname, phone FROM warrantydb ORDER BY lname ASC"); 

echo "<select name=\"DropData\">";

while($row = mysql_fetch_array( $result )) 
{
      //I figure there is a more refined way of doing this, but this works for me. Any thoughts would be appreciated.
        $Data=$row['lname'];
$Data2=$row['fname'];
$Data3=$row['phone'];

        echo "<option>$Data $Data2 $Data3</option>";
}

echo "</select>";
?> 

Link to comment
Share on other sites

You need to some way add an identifier into the options. If you have an "id" field in the warrantydb table you can modify your query for this:

 

SELECT id,lname, fname, phone FROM warrantydb ORDER BY lname ASC

Now assign this into a variable:

$id=$row['id'];

 

Now, when you add the options, use this line:

echo "<option value=\"$id\">$Data $Data2 $Data3</option>";

 

Now read the id field...

 

POST:

$warrantyid=$_POST['DropData'];

 

GET:

$warrantyid=$_GET['DropData'];

 

Link to comment
Share on other sites

I appreciate all your time and assistance on this, thank you. I tried your example and although it allows me to select an option from the drop down, I don't know how to get all the data associated with this person to be displayed in the form. I have the form all set up and working well, it includes address, address2 city, state and zip, is there a way to have this information populated in the correct fields for the person chosen?

 

Thank you so much again!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.