Witajcie. Mam tabelę w Bootstrap, w której chciałbym, aby po kliknięciu na "+" pokazywał się dodatkowy wiersz, w którym byłaby przypisana dana wartość z z bazy sql. Poniżej kod:
<table id="table" data-toggle="table" data-cache="false" data-show-columns="true" ata-click-to-select="true" data-toolbar="#toolbar" data-search="true" data-pagination="true" data-page-size="500" data-show-refresh="false" data-url="data.php" data-detail-view="true" data-filter-control="true" data-detail-formatter="detailFormatter">
<thead>
<th data-field="zdjecie" data-formatter="imageFormatter" data-sortable="true" data-tooltip="true" ></th>
<th data-field="marka" data-sortable="true" class="text-center" >Marka</th>
<th data-field="model" data-sortable="true" class="text-center" >Model</th>
<th data-field="lcd" data-sortable="true" class="text-center">Wyświetlacz</th>
<th data-field="cena" data-sortable="true" class="text-center" >Cena</th>
<th data-field="numermodelu" data-sortable="true" class="text-center" >Numer Modelu</th>
<th data-field="rodzajlcd" data-sortable="true" class="text-center">Rodzaj Wyświetlacza</th>
<th data-field="ppi" data-sortable="true" class="text-center" >Nasycenie</th>
<th data-field="rozdzielczosc" data-sortable="true" class="text-center" >Numer Modelu</th>
<th data-field="najnizszacena"> </th>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
function imageFormatter(value, row) {
return '<img src="'+value+'" width= "50px" height= "50px" />';
}
function detailFormatter(index, row) {
var html = [];
$.each(row, function (key, value) {
html.push('<p><b>' + key['cena'] + ':</b> ' + value['cena'] + '</p>');
});
return html.join('');
}
</script>
Oraz plik data.php
require 'configbase.php';
$stmt = $db->query('SELECT * FROM smartfony');
$arrVal = array();
$i=1;
while($rowList = $stmt->fetch()){
$name = array(
'id' => $i,
'lcd'=> $rowList['typscreen'],
'cena'=> $rowList['cenatelefonu'],
'marka' => $rowList['marka'],
'model' => $rowList['model'],
'numermodelu' => $rowList['numermodelu'],
'zdjecie'=> 'http://www.aaaaa.pl' . $rowList['zdjecie'],
'ilosckolorow'=> $rowList['ilosckolorow'],
'rozmiar'=> $rowList['rozmiar'],
'rozdzielczosc'=> $rowList['rozdzielczosc'],
'ppi'=> $rowList['ppi'],
'rodzajLCD'=> $rowList['rodzajLCD'],
);
array_push($arrVal, $name);
$i++;
}
echo json_encode($arrVal);