Topic: Bootstrap datatable- No data available out of an php array
Hello,
I use the following script:
<script>
import { mdbDatatable2, mdbContainer } from 'mdbvue';
export default {
components: {
mdbDatatable2,
mdbContainer
}
};
</script>
And this is my table which I create out of an php array:
echo '<table id="dtBasicExample" class="table table-striped table-bordered table-sm" cellspacing="0" width="100%">';
echo '<tbody>';
echo '<thead>';
echo '<tr>';
echo '<th>';
echo "Charakterid";
echo '</th>';
echo '<th>';
echo "Serverid";
echo '</th>';
echo '<th>';
echo "Level";
echo '</th>';
echo '<th>';
echo "";
echo '</th>';
echo '</tr>';
echo '</thead>';
echo '<tr>';
echo '<td>';
echo $head['name'];
echo '</td>';
echo '<td>';
echo $head['transmog']['item']['id'];
echo '</td>';
echo '<td>';
echo $head['item']['id'];
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $neck['name'];
echo '</td>';
echo '<td>';
echo $shoulder['transmog']['item']['id'];
echo '</td>';
echo '<td>';
echo $neck['item']['id'];
echo '</td>';
echo '</tr>';
echo '<td>';
echo $chest['name'];
echo '</td>';
echo '<td>';
echo $chest['transmog']['item']['id'];
echo '</td>';
echo '<td>';
echo $chest['item']['id'];
echo '</td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
?>
I get the tables data out of an extern API json array, which I decode in a php array:
function getSslPage4($url4, $userAgent4)
{
$ch4 = curl_init($url4);
curl_setopt($ch4, CURLOPT_USERAGENT, $userAgent4);
curl_setopt($ch4, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch4, CURLOPT_HEADER, false);
curl_setopt($ch4, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch4, CURLOPT_URL, $url4);
curl_setopt($ch4, CURLOPT_REFERER, $url4);
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, TRUE);
$result4 = curl_exec($ch4);
curl_close($ch4);
return json_decode($result4, true);
}
$url4 = "https://eu.api.blizzard.com/profile/wow/character/xx/xxx/equipment?
namespace=profile-eu&locale=de_DE&access_token=$token";
$array = getSslPage4($url4, $userAgent4);
After that I call the data out of the php array with a foreach loop and echo them out in my table.
$named_slots = [];
foreach ($array['equipped_items'] as $item) {
$named_slots[$item['slot']['type']] = $item;
The problem is that the "Bootstrap table" shows
"No data available in table".
Since it isn´t a json array anymore I dont think that I need to use the API. How can I fix this in an easy way?
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Open
- User: Free
- Premium support: No
- Technology: MDB Vue
- MDB Version: 6.7.1
- Device: PC
- Browser: every browser
- OS: Bootstrap table
- Provided sample code: No
- Provided link: No
Magdalena Dembna staff premium commented 4 years ago
I'm not quite getting what you're trying to achieve - the data for Datatable2 needs to be formatted in a specific way (checkout data structure here: https://mdbootstrap.com/docs/vue/tables/datatables/#docsTabsAPI) and passed to the component via properties. The easiest way would be to fetch an array, transform data to a required format add pass it to the component.