Tips, Trick, Mengatasi Masalah Komputer, Membina Website & Programming

PHP Code : Identify NULL Field / Kenal pasti field kosong

<?php 
require_once('connect.php');

mysql_select_db($database_connect, $connect);
$query_record = "SELECT * FROM tablename";
$record = mysql_query($query_record, $connect) or die(mysql_error());
$row_record = mysql_fetch_assoc($record);
$totalRows_record = mysql_num_rows($record);

?>

//Display Data
<?php 
if($row_record['fieldname']==NULL)
{
   echo "Field Name Kosong";
}
else
{
   echo $row_record['fieldname'];
}
?>

PHP Code : Identify Empty Record / Kenal pasti Rekod Kosong


<?php 
require_once('connect.php');

mysql_select_db($database_connect, $connect);
$query_record = "SELECT * FROM tablename";
$record = mysql_query($query_record, $connect) or die(mysql_error());
$row_record = mysql_fetch_assoc($record);
$totalRows_record = mysql_num_rows($record);

?>

//Display Data
<?php 
if($totalRows_record==NULL)
{
   echo "Tiada Rekod";
}
else
{
   echo $row_record['fieldname'];
}
?>

PHP Code : Show Record With BreakLine / Paparkan Rekod Dengan Break Line

Masalah : Apa bila paparkan rekod dari database. Data yang sepatutnya ada [Enter] / Breakline tapi tidak ada. Maksudnya data akan jadi satu line sahaja. Bersambung-sambung tanpa ada perenggan atau jarak bawah dan atas.

[Solve] 
Code :

<?php 
 echo nl2br("Perkataan disini");
?>

Blogger templates