Last active
January 23, 2019 13:08
-
-
Save fannyhasbi/3126d65d1daed4970d774194887c0f77 to your computer and use it in GitHub Desktop.
Force show empty value of a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$conn = mysqli_connect("localhost", "root", "", "test") or die(mysql_error()); | |
function check_len($arr, $index, $key){ | |
if(array_key_exists($index, $arr)){ | |
return $arr[$index][$key]; | |
} | |
return ""; | |
} | |
function show_data($data, $count){ | |
for($i = 0; $i < $count; $i++){ | |
echo | |
'<tr>'. | |
'<td>'. check_len($data, $i, "id_buku") .'</td>'. | |
'<td>'. check_len($data, $i, "harga_buku") .'</td>'. | |
'<td>'. check_len($data, $i, "penerbit") .'</td>'. | |
'</tr>'; | |
} | |
} | |
$query = "SELECT id_buku, harga_buku, penerbit FROM buku LIMIT 2"; | |
$hasil = mysqli_query($conn, $query); | |
$output = array(); | |
while($row = mysqli_fetch_assoc($hasil)){ | |
$angka = array_push($output, $row); | |
} | |
?> | |
<table border="1" cellspacing="0" cellpadding="5"> | |
<?php show_data($output, 3); ?> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment