I'm having trouble trying to get data from a database. The code will only retrieve the first row of data from the Database. The data is correct but it does not matter what information I put into my html input field the data is the same in the new row that is added. Any help resolving this would be fantastic.
If someone was going to point out that I have both "POST" and "GET" mixed in my code, I could understand as that being a possible problem, but neither when matching would retrieve data from the DB, other than the first row of data in the table.
Any help with this would be great!!! Thanks to all who provide an answer in advance.
My HTML code:
index.php
<div class="row">
<div class="col-md-1"></div>
<div class="col-xs-3">
<h3 class="h4 text-center"><input type="text" name="barcode" id="barcode" size="90" class="col-md-9" value="" method="GET" placeholder="Barcode / Product Name"></h3>
</div>
</div>
<br />
<div class="row">
<div class="col-md-1"><p class=""></p></div>
<div class="col-md-6">
<table id="report" class="table table-bordered table-hover">
<thead>
<tr>
<td>SKU</td>
<td>Model</td>
<td>Item Description</td>
<td>Qty</td>
</tr>
</thead>
<tbody>
<?php get_item(); ?>
</tbody>
</table>
</div>
</div>
This is my AJAX script
<script>
var inp = $("#barcode");
// where #txt is the id of the textbox
$("#barcode").keyup(function (event) {
if (event.keyCode == 13)
{
if (inp.val().length > 0)
{
$.ajax({
url: "index.php",
type: "GET", //Also tried POST method. Didn't work either
data: {id: inp.val()},
success: function(response)
{
values = response.split(' - ');
$('#report tr:last').after(
"<tr class='table-row'>" +
"<td class=''>" + values[1] + "</td>" +
"<td class=''>" + values[2] + "</td>" +
"<td class=''>" + values[3] + "</td>" +
"<td class=''>" + values[4] + "</td></tr>");
}});
}
$('input[name=barcode]').val('');
}
});
</script>
Here is my php code
function get_item(){
global $con;
if(!empty($_POST))
{
$query = query("SELECT * FROM items");
confirm($query);
while($row = fetch_array($query)) {
$sku = $row['sku'];
$model = $row['category'];
$desc = $row['description'];
$qty = $row['qty'];
echo($id.' - '.$sku.' - '.$model.' - '.$desc.' - '.$qty);
die();
}
}
}
Move the die(); function call out of your while loop. It gets called rigth at the end of the first loop terminating your php script.
Related
My HTML code is very simple :
<body>
<form id="delForm" action="deleteThirdMulti.php" method="post"> <!--Le fomulaire qui ne sert que pour les checkbox-->
<div class="container">
<div class="col-md-1 pull-right">
<img src="CSS/PICTURES/add.png" />
<br /><br />
</div>
<div class="row">
<div class="col-md-2 form-group">
<button type="submit" class="btn btn-default" name="delete_all">Supprimer</button>
</div>
<div class="col-md-2 form-group">
<select name="choix_service" class="form-control form-update-user" id="sort">
<option selected="selected">TOUS</option>
<option value="COMPTABILITE">CLIENT</option>
<option value="EXPLOITATION">AFFRETE</option>
<option value="INFORMATIQUE">PROPRIETAIRE</option>
</select>
</div>
</div>
<table class="table table-condensed table-responsive table-bordered sortable table-striped" id="table">
<thead>
<tr>
<th class="text-center"><input type="checkbox" onclick="toggle(this)" name="check_all"/></th>
<th class="text-center">Type</th>
<th class="text-center">Code</th>
<th class="text-center">Nom</th>
<th class="text-center">Adresse 1</th>
<th class="text-center">Adresse 2</th>
<th class="text-center">Code Postal</th>
<th class="text-center">Ville</th>
<th class="text-center">Pays</th>
<th class="text-center">Téléphone</th>
<th class="text-center">Fax</th>
<th class="text-center">E-mail</th>
<th class="text-center">Site web</th>
</tr>
</thead>
<tbody>
And then, I have a PHP code which display datas from the database.
The problem is that I would like the user to be able to change the value in the select box and, I would like the datas to be updated without a page reload. Indeed, when I select CLIENT, only CLIENTS from the base will be displayed in the table.
My start of Jquery code :
<script type="text/javascript">
$(document).ready(function() {
$('#sort').change(function(){
var valeur = $('#sort option:selected').text();
$.ajax({
url: 'some-url',
type: 'post',
dataType: 'json',
data: valeur,
success: function(data) {
... do something with the data...
}
});
})
});
</script>
Inside your Success function on the Ajax call you will want to loop through the data and use jquery's
.html(text)
function to fill in the table data.
It may be easier to wrap the table id="table" inside a div container so you can write the entire table HTML from within your success function in the AJAX.
I hope this addresses your question, it was a little unclear what you are trying to accomplish, but it seems there is some language barriers here that we can hopefully overcome.
Let me know if you need any clarification on things!
Clarification for comment #1:
create a div on the page for your ajax response information. Let's call this "clients_table_container"
<div id="clients_table_container"></div>
When your ajax response success function is called, you can fill the content of this container div with the html code you would like to display. For Example:
success: function(data)
{
//TODO: Turn JSON into html string content
var my_html_string = data;
//REPLACE THE CONTENT IN THE DIV WITH THIS DATA
$('#clients_table_container').html(my_html_string);
}
You'll want to make sure you have the <table> html inside the my_html_string variable and you fill in the <tr><td></td></tr> tags based on the json response in the data variable. This part you will have todo as we have no visibility into it's contents.
It works !
This is my code in the AJAX PHP file :
<?php
include('../sqlConnexion.php');
include('../security.php');
if ($_POST['valeur'] == 'TOUS')
{
$req = $bdd->query('SELECT * FROM tiers ORDER BY code');
$response['i'] = $_POST['valeur'];
}
else
{
$req = $bdd->prepare('SELECT * FROM tiers WHERE type = :type ORDER BY code');
$req->execute(array(
'type' => $_POST['valeur']
));
}
$response['table'] = '';
$i = 0;
while ($third=$req->fetch())
{
$response['table'] = $response['table'] . "<tr>
<td align='center'><input type='checkbox' name='delete_$i' value='".$third['id']."'></td>
<td align='center'>" . $third['type'] . "</td>
<td align='center'>" . $third['code'] . "</td>
<td align='center'>" . $third['nom'] . " </td>
<td align='center'>" . $third['adresse1'] . " </td>
<td align='center'>" . $third['adresse2'] . " </td>
<td align='center'>" . $third['cp'] . " </td>
<td align='center'>" . $third['ville'] . " </td>
<td align='center'>" . $third['pays'] . " </td>
<td align='center'>" . $third['telephone'] . " </td>
<td align='center'>" . $third['fax'] . " </td>
<td align='center'>" . $third['email'] . " </td>
<td align='center'><a target='blank_' href='" . $third['website'] . "'>" . $third['website'] . " </td>
<td align='center'><a href='updateThird.php?id=" . $third['id'] . "'><img src='CSS/PICTURES/modification.jpg' title='Modifier le tiers'/></a></td>
</tr>";
$i++;
}
$req->closeCursor();
echo json_encode($response);
Here is my JQuery code with filling the 'tbody' :
$(document).ready(function() {
$('#sort').change(function(){
var valeur = $('#sort option:selected').text();
//window.location.replace('thirdManagement.php?third=' + valeur);
$.ajax({
url: 'MODEL/ajaxSearchThirds.php',
type: 'post',
dataType: 'json',
data: {'valeur': valeur},
success: function(data) {
$('tbody').html(data.table);
$('#ivalue').val(data.i);
}
});
})
});
Hope it will help someone.
This is my following code in front End:
<div class="panel panel-primary">
<div class="panel-heading text-center text-uppercase">Birth Certificates For Overall (Pending, Completed)</div>
<div class="panel-body">
<div class="box-body">
<table id="viewer" class="table table-bordered">
<thead>
<tr>
<th>Sr No</th>
<th>Reg Number</th>
<th>From Hospital</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $Viewer->showAllData(); ?>
</tbody>
<tfoot>
<tr>
<th>Sr No</th>
<th>Reg Number</th>
<th>From Hospital</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div>
This is my classes code in it of which i have called the object:
public function showAllData()
{
$query = "SELECT * FROM certificate_details ORDER BY created DESC";
$connection = $this->establish_connection();
$details = $connection->query($query);
$connection->close();
if($details->num_rows > 0)
{
$counter = 1;
while($detail = $details->fetch_assoc())
{
$status = $detail['status'];
if($status == 0)
{
$bg = "bg-danger";
$issuestatus = "btn btn-success";
$message = "Confirm Issue!";
}
elseif($status == 1)
{
$bg = "bg-success";
$issuestatus = "btn btn-success disabled";
$message = "Certificate Issued";
}
else
{
$bg = "bg-warning";
$issuestatus = "btn btn-warning";
}
echo "
<tr class='odd gradeX ".$bg."'>
<td>".$counter."</td>
<td>".$detail['registration_number']."</td>
<td>".$this->getHospitalInfo($detail['user_id'])."</td>
<td style='margin: 0;'><div class='btn btn-primary' href='#' value='".$detail['id']."' id='view-details'>View Details</div><div style='margin-left: 10px;' class='".$issuestatus."' href='#' value='".$detail['id']."' id='confirm-issue'>".$message."</div></td>
</tr>
";
$counter = $counter + 1;
}
}
}
I have give a specific id to the button i.e id="view-details" and in the value section it hold the unique value
This is the following JQuery Code which i am triggering whenever i am calling the ("#view-details").click(function(){})
$("#view-details").click(function()
{
var certificateId = $("#view-details").attr('value');
$.ajax({
url: 'get_data.php?id=getCertificateDetails',
type: 'POST',
dataType: 'html',
data: {certificate_id : certificateId},
})
.done(function(resp)
{
var data = $.parseJSON(resp);
if(data.status == 1)
{
var message = "Certificate is Already Issued";
var btn_status = "btn btn-success disabled";
}
else if(data.status == 0)
{
var message = "Click To Confirm Issue!";
var btn_status = "btn btn-danger";
}
else
{
var message = "Technical Issue";
var btn_status = "btn btn-danger disabled";
}
var data = "<div class='modal-dialog'>"+
"<div class='modal-content'>"+
"<div class='modal-header' align='center'>"+
"<h3 class='modal-title'>Certificate Details Are As Follows</h3>"+
"</div>"+
"<div class='modal-body'>"+
"<b>Registration Number</b> : "+data.reg_number+
"<br /><b>Baby's Birth Date</b> : "+data.birth_date+
"<br /><b>Baby's Birth Time</b> : "+data.birth_time+
"<br /><b>Baby's Gender</b> : "+data.gender+
"<br /><b>Baby's Full Name</b> : "+data.baby_name+
"<br /><b>Father's Full Name</b> : "+data.fathers_name+
"<br /><b>Mother's Full Name</b> : "+data.mothers_name+
"<br /><b>Parent's Address While Baby's Birth</b> : "+data.while_baby_birth_parents_address+
"<br /><b>Parent's Permanent Address</b> : "+data.parents_permanent_address+
"<hr /><h4 class='text-center'>Hospital Details</h4>"+
data.hospital_detail+
"<hr /><h4 class='text-center'>Home Details</h4>"+
data.home_detail+
"<hr /><h4 class='text-center'>Other Details</h4>"+
data.other_detail+
"</div>"+
"<div class='modal-footer'>"+
"<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>"+
"<a href='#' class='"+btn_status+"' id='confirm-issue'>"+message+"</a>"+
"</div>"+
"</div>"+
"</div>";
$('#viewDetails').html(data);
$('#viewDetails').modal('show');
})
.fail(function()
{
console.log("error");
});
});
The problem arises when lets take a scenario
have a look at this screenshot
when i click on view details of the very first record the modal is called, but when i click on the next view details the modal doesn't appear. it seems that the modal appears only for the very 1st record present in the table
please can anyone help me with this code
you are generating multiple elements with the same id ("view-details"). That's invalid HTML. Element IDs must be unique. Your click event handler will only work on the first one because it considers that all the later ones are not valid.
Use classes instead (e.g. $( "body" ).on( "click", ".view-details"... instead of $("#view-details").click(... and <div class='btn btn-primary view-details'... as the button (instead of id="view-details")
#view-details id always unique so your modal will only work with first where ever it comes.
For more details about Difference between id and class in CSS and when to use it
so you need to add a class to open model, and some change in your code
HTML :
id='view-details' to <div class='btn btn-primary view-details'>
JS:
$( "body" ).on( "click", ".view-details", function() {
var certificateId = $( this ).attr('value');
// .... Rest of your code here
});
Why Use jQuery .on() because it will bind click handler to every button holding view-details class.
var certificateId = $( this ).attr('value');
Will give you current clicked button's attribute value.
this is my edit_table.php in which dynamic table is generated and by on click function i try to update database.
<script>
function table_edit(btn)
{
var id=btn.id;
if(btn.value=="Edit")
{
document.getElementById('college_id'+id).setAttribute("contenteditable" , "true");
document.getElementById('name'+id).setAttribute("contenteditable" , "true");
//document.getElementById('university_id'+id).removeAttribute("Readonly");
document.getElementById('university_id'+id).setAttribute("contenteditable" , "true");
document.getElementById(id).value="Save";
return false;
}
if(btn.value=="Save")
{
document.getElementById('name'+id).removeAttribute("contenteditable");
document.getElementById('college_id'+id).removeAttribute("contenteditable");
// document.getElementById('university_id'+id).setAttribute("Readonly" , "readonly");
document.getElementById('university_id'+id).removeAttribute("contenteditable");
document.getElementById(id).value="Edit";
var newuniversity_id=document.getElementById('university_id'+id).innerHTML;
var newcollege_id=document.getElementById('college_id'+id).innerHTML;
var newname=document.getElementById('name'+id).innerHTML;
alert(newname+" "+newcollege_id+" "+newuniversity_id+" "+id);
var dataString = 'name1=' + name + '&university_id=' + newuniversity_id + '&college_id=' + newcollege_id + '&id=' + id;
$.ajax({
type: "POST",
url: "update_table_data",
data: dataString,
success: function(html) {
alert("ajax calling done");
}
});
return true;
}
}
function table_update(){
//document.getElementById("edit_rows").value="Save"
alert("Working!");
}
</script>
<?php
function test()
{
echo "<script>alert('hello');</script>";
} ?>
<div id="page-content-wrapper">
<div class="container-fluid">
<i class="fa fa-bars"></i> <span>Menu</span>
<div class="content-block">
<div class="login-sign forgot_pass login forgot text-center">
<!-- <form action="<?php echo base_url(); ?>edit_table" method="post" accept-charset="utf-8"> -->
<div class="login-signup-head">Edit Table</div>
<table>
<tbody>
<thead>
<tr class="tredit">
<!-- <th width="10"></th> -->
<th> Id </th>
<th > University Id </th>
<th > Name </th>
<th > College Id </th>
<th width="100"> </th>
</tr>
</thead>
<tbody>
<?php
foreach($student_data as $row){
?>
<tr class="tredit" id="row_edit">
<td><?php echo $row['id']; ?></td>
<td id="university_id<?php echo $row['id']; ?>" ><?php echo $row['university_id']; ?></td>
<td id="name<?php echo $row['id']; ?>" ><?php echo $row['name']; ?></td>
<td id="college_id<?php echo $row['id']; ?>" > <?php echo $row['college_id']; ?></td>
<td><input type='button' class='editable' onclick=" return table_edit(this)" value='Edit' id= "<?php echo $row['id']; ?>">
<input type='button' class='tabledelete' onclick="table_update()" value='Delete' ></td>
</tr>
<?php
}
?>
</div>
</div>
</div>
<!-- </form> -->
</div>
</div>
</tbody>
</table>
and this is the route
$route['update_table_data'] = 'home/update_table';
and the following functions are for fetching the data as well as updating the data.
public function tableedit(){
if($this->session->userdata('university_id')){
$user_id = $this->session->userdata('university_id');
$data['user_id'] = $user_id;
$data['student_data'] = $this->home_model->table_data($user_id);
$this->load->view('home/new-header',$data);
$this->load->view('home/left_university_sidebar',$data);
$this->load->view('edit_table',$data);
$this->load->view('home/footer');
} else {
$data['error'] = 'Table Cannot be viewed!';
$this->load->view('home/header');
$this->load->view('edit_table');
$this->load->view('home/footer');
}
}
public function update_table() {
if($this->session->userdata('university_id')){
if($this->input->server("REQUEST_METHOD") === "POST"){
$university_id=$_POST['university_id'];
$college_id=$_POST['college_id'];
$id=$_POST['id'];
$name=$_POST['name'];
$this->home_model->update_table($university_id,$college_id,$name,$id);
}
}
}
and finally this is the model for update query.
public function update_table($university_id,$college_id,$name,$id) {
$data = array('University Id' => $university_id, 'name' => $name, 'College Id' => $college_id);
$this->db->where('id', $id);
$this->db->update('college', $data);
}
editable table
edit values
but when i save and refresh the page, no change occur in the table.
my issue is database is not updated when i update it from save button.
first of all :
Formatting your code , that must be clean and easily readable
for your ajax call you dont need use routed url , it work at background, you can use like this :
put : <script>var base_url='<?php echo base_url(); ?>'</script>
in your header menu , or upper place that you use in your theme.
then make ajax call like this:
$.ajax({
type: "POST",
url: base_url+"youController/yourAction",
data: dataString,
success: function(html) {
alert("ajax calling done");
}
});
I'm trying to print the data from the sql for record purposes but I'm using datatable so when I try to click print, the record doesn't show everything. It only shows the current data from the page 1 of the datatable. How will I do it? Plus, when I tried printing it, the display also shows the include function of the php. Javascript solutions are allowed. Here is my code
<?php include ('sidebar.php'); ?>
<main id="playground">
<?php include ('header.html'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<section class="panel panel-info">
<header class="panel-heading">
<h4 class="panel-title">List of employees</h4>
</header>
<div class="panel-body">
<?php
include('configuration.php');
$sql = "SELECT firstname, lastname, status, idnumber FROM employees ORDER BY lastname ASC";
$result = $conn->query($sql);
?>
<table class="table table-striped datatable" id="datatables" >
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>ID Number</th>
</tr>
</thead>
<?php
if ($result->num_rows > 0) { // output data of each row?>
<tbody>
<button onclick="myFunction()">Print this page</button>
<?php while($row = $result->fetch_assoc()) {
if($row['status']=='p'){
?>
<?php { //this form will display the set of pending applications
echo'<tr>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['idnumber'] . '</td>';
echo'</tr>';
}
?>
<?php } //if statement
} //while statement
?>
</tbody>
</table>
<?php
}else {
echo "0 results";
}
?>
</div>
</section>
<!-- end of STRIPED ROWS TABLE -->
</div> <!-- / col-md-12 -->
</div> <!-- / row -->
</div> <!-- / container-fluid -->
</main> <!-- /playground -->
<?php include ('notifications.html'); ?>
<div class="scroll-top">
<i class="ti-angle-up"></i>
</div>
</div> <!-- /animsition -->
<script>
function myFunction() {
window.print();
}
</script>
</body>
</html>
Please use
$('#datatables').DataTable( {
buttons: [
'print'
]
} );
Please check Document and Reference
Use Below 2 functions:
function CreateTableFromObject(tblObj) {
objHeader = JSON.parse(JSON.stringify(tblObj.buttons.exportData()))["header"];
objRows = JSON.parse(JSON.stringify(tblObj.buttons.exportData()))["body"];
//Check If Action Exists in Table and remove it
var index = objHeader.indexOf('Action');
if (index > -1) {
objHeader.splice(index, 1);
}
tblToPrint = "<table style='border: 1px solid black; border-collapse: collapse;'><thead><tr>";
$.each(objHeader, function (key, value) {
tblToPrint += "<th style='border: 1px solid black;'>" + value + "</th>";
});
tblToPrint += "</tr></thead><tbody>";
$.each(objRows, function (key, value) {
tblToPrint += "<tr>";
//If action exists then decrease target by 1
if (index > -1) {
target = value.length - 1;
}else {
target = value.length;
}
for (var i = 0; i < target; i++) {
tblToPrint += "<td style='border: 1px solid black;'>" + value[i] + "</td>";
}
tblToPrint += "</tr>";
});
tblToPrint += "</tbody></table>";
return tblToPrint;
}
function PrintWindowAddParts() {
var tblObj = $("#YourTable").DataTable();
var tblViewRMA = CreateTableFromObject(tblObj);
var printContents = "<div class='dataTables_wrapper form-inline dt-bootstrap'>" + tblViewRMA + "</div>";
var size = 'height=' + $(window).height() + 'px,width=' + $(window).width() + 'px';
var mywindow = window.open('', 'PRINT', size);
mywindow.document.write('<html><head><title>' + "My Title" + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h4>' + "My Title" + '</h4>');
mywindow.document.write(printContents);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
return true;
}
Your Print function is Ready.
I am looping through a mysql table and printing an HTML "Play" link for each row.
I'm trying to avoid refreshing the page on every click of the 'Play' link so I'm placing javascript in the link's 'href':
<a href='javascript:void(0)' onclick='playMV(\"".$rows["v_type"]."\",\"".$rows["v_id"]."\");'>Play</a>
The playMV() function will send necessary info to the server via jquery ajax post to get back out needed values. The php script on the server will use the values posted as values in a mysql query.
// javascript:
<script type="text/javascript">
function playMV(p1, p2) {
$.post("?opt=music", {
var1: p1,
var2: p2
}, function (data) {
//$('#result').html(p2);
});
}
</script>
// PHP:
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
$q = mysql_query("SELECT * FROM table WHERE v_lang='".$var1."' AND v_id='".$var2."'");
My question is: I don't know how to call both 'p1' and 'p2' values and assigned into php variable. the commented line $('#result').html(p2) was only output the values in a div block with id='result' but don't really can get it pass to php. I've been read through some answer regarding on json stuffs but end up can't even get what I want.
Please help as I've been stuck quite long in this part.
Thanks very much!!!
// whole code
<script type="text/javascript">
function playMV(p1, p2) {
$.post("<?php echo curPageURL() ?>", {
var1: p1,
var2: p2
}, function (data) {
//$('#result').html(p2);
//$('#result').html(data);
});
}
</script>
<?php
mysql_set_charset("utf8");
$var1 = $_POST['var1'];
$mvid = $_POST['var2'];
echo $var1.$var2;
//echo var_dump($_POST);
$count = 1;
if((strpos(curPageURL(),'mv')==false) || (strpos(curPageURL(),'type')==false)){
$type = ucwords("C");
$mvid = 1;
}
$mtv_data = array();
$mtvlist = mysql_query("SELECT * FROM ".$tb01." WHERE mtv_type='".$type."' ORDER BY mtv_order ASC LIMIT 0, 10") or die(mysql_error());
while($rows = mysql_fetch_array($mtvlist)){
$mtv_data[] = $rows;
}
$q = mysql_query("SELECT * FROM ".$tb01." WHERE mtv_id='".$mvid."'") or die(mysql_error());
$r = mysql_fetch_array($q);
?>
<span id="result"></span>
<div align="center" class="content-layer1" style="height:600px;padding-bottom:20px;">
<div class="content-layer2">
<div style="width:900px;text-align:left;padding:18px 18px 8px 18px;">
<h1>MUSIC ZONE</h1>
</div>
<div style="width:900px;text-align:left;padding:10px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="55%">
<div id='mediaspace' align='center'>
<img src="images/ajax-loader.gif">
</div>
<div><?php echo $r["mtv_title"] ?><br /><?php echo $r["mtv_artist"] ?> </div>
</td>
<td width="45%" valign="top">
<div style="border:0px #000 solid;">
<table width='100%' border='1' cellspacing='2' cellpadding='2'>
<?php
foreach($mtv_data as $rows){
echo "<tr>
<td>".$count."</td>
<td><div>".$rows["mtv_title"]."</div><div>".$rows["mtv_artist"]."</div></td>
<td><a href='javascript:void(0)' onclick='playMV(\"".$rows["mtv_type"]."\",\"".$rows["mtv_id"]."\");' id='playmv'>Play</a>
</td>
</tr>";
$count += 1;
}
?>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
use json_decode()
$object = json_decode(json_string)