action.php could not fetch the data from the database table
So i have to display out the row in a table that fetch from my database. I have a JQuery to fetch out code but it show me the error
Parse error: syntax error, unexpected ';' in C:xampphtdocshopeplacemadminaction.php on line 49
<?php
//action.php
if(isset($_POST["action"]))
{
include('../connect.php');
if($_POST["action"] == 'fetch')
{
$output='';
$query ="SELECT * FROM user_details WHERE user_type ='user' ORDER BY user_name ASC";
$statement = $Conndb-> prepare($query);
$statement->execute()
$result = $statement->fetchAll();//line 14
$output .= '
<table class="table table-hover">
<tr>
<td>Full Name</td>
<td>Email</td>
<td>Status</td>
<td>Action</td>
</tr>
';
foreach($result as $row){
$status ='';
if($row["user_status"] == 'Active'){
$status = '<span class="label label-success">Active</span>';
}
else{
$status = '<span class="label label-danger">Inactive</span>';
}
$output .= '
<tr>
<td>'.$row["user_name"].'</td>
<td>'.$row["user_email"].'</td>
<td>'.$status.'</td>
<td><button type="button" name ="action" class="btn btn-info btn-xs action" data-user_id="'.$row["user_id"].'" data-user_status="'.$row["user_status"].'">Action</button></td>
</tr>
';
}
$output .= '</table'>;//line 49
echo $output;
}
}
?>
even I change the code to
$output .= '</table>';//line 49
it show me another error
Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetchAll() in C:xampphtdocshopeplacemadminaction.php:14 Stack trace: #0 {main} thrown in C:xampphtdocshopeplacemadminaction.php on line 14
fetchAll()
is for PDO.
fetch_all()
is for MySQLi, which is seems like you're using.
You have mixed up PDO and mysqli. Try below code replacement which does the same with mysqli. $output='';
$stmt = $this->db->prepare($query);
$stmt->execute();
//grab a result set
$resultSet = $stmt->get_result();
//pull all results as an associative array
$result = $resultSet->fetch_all();
链接地址: http://www.djcxy.com/p/69426.html