How to insert separate field into one?
Example:
In your database the 1 table name tbl_applicant composed of the following fields...
|id | lastname | firstname | middlename|
And you wonder that if you want to get the data you have to transfer in one place by using combobox/list...
Example:
I have this table named " tbl_results ".. and i want to show the names from tbl_applicant in their correct format so it look like this:
Here the code if you want to display 3 fields.. in a combobox..
Code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("er", $con);
$name= mysql_query("SELECT * from tbl_applicant ORDER by lastname ASC");
echo '<select name="aname" class="mySelect3">';
echo '<option>---SELECT NAMES---</option>';
while($res= mysql_fetch_assoc($name))
{
echo '<option>';
echo $res['lastname'].' ,'.$res['firstname'].''.$res['middlename'];
echo'</option>';
}
echo'</select>';
mysql_close($con)
?>
the Output is the picture on upper side before this text..
if you want to insert this into database you have to name the insert query into "aname"..
Here's the code:
if(isset($_POST["submit"]))
{
$insdb ="INSERT INTO tbl_results(applicant_name) VALUES
('$_POST[aname]')";
mysql_query($insdb,$link);
echo "<script>alert('Successfully Added!')</script>";
}
That's it!
If you have question regarding this topic or OT that is not understandable in you part, don't hesitate to comment below..
thanks..
Thanks.
Status: Done!
No comments:
Post a Comment