I am complete beginner I want to display comma separated values from database in tabular form
From the below image link we can see how the data is getting added separated by commas:
I want to display in tabular form in html/php page just like below:
This is my html page below:-
<form action="insert.php" method="POST">
<div id="items">
<input type="text" placeholder="name" name="user_name[]" />
<input type="text" placeholder="email" name="user_email[]" />
</div>
<input type="button" value="add entry" id="add"/>
<input type="submit" value="submit"/>
Javascript file for adding additional input:-
$(document).ready(function(){
$("#add").click(function (e){
event.preventDefault()
$('#items').append('<div><input type="text" placeholder="Name" name="user_name[]" ><input type="text" placeholder="email" name="user_email[]">'
+'<input type="button" value="delete" id="delete"/></div>');
});
$('body').on('click','#delete',function(e){
$(this).parent('div').remove();
});
});
And below is the PHP code for inserting to database:-
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dynamic", $con);
$user_name = $_POST["user_name"];
$value = implode(',', $user_name);
$user_email = $_POST["user_email"];
$valueone = implode(',', $user_email);
$sql="INSERT INTO dynamicdata (user_name, user_email)
VALUES
('$value','$valueone')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
Just fetch the data from the table and explode both
username
anduseremail
to make array and just loop it and diplay the values.Below pasted code may help you.
Please understand this nd try to implement in your code.