require("conn.php");
$sql = "select * from pemohon where kp_baru='$kp';";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
    if($row == TRUE)
    {
     echo $row['kp_baru']; // can display
    }
    else
    {
        echo "No KP tiada didalam pangkalan data."; // can't display
    }
}

Recommended Answers

All 9 Replies

What is your question?

line 12 can't display at the browser...

$sql = "select * from pemohon where kp_baru='$kp';";
the first semi-colon (;) is un-neccessary.
Try

if($row['kp_baru']=='')
{
 echo "No KP tiada didalam pangkalan data."; 
}
else
{
    echo $row['kp_baru']; 
}

instead.

I'm not certain, but I think your $row will always be true. It contains an array with the result set from your query.
You need to select a value in each row of your query to check.
Another tip - try and avoid SELECT * FROM ... Rather select specific fields. That way there's less data being retrieved from the database and the query will run faster.

SELECT field1, field2, field3, `kp_baru` FROM pemohon where kp_baru='$kp';
...
while($row = mysql_fetch_array($result)) 
{
    if (field2 == requiredvalue) 
    {
         echo $row['kp_baru'];
    }
    else
    {
        echo "No KP tiada didalam pangkalan data.";
    }
}

I hope this helps... :-)

still give blank page

Then have you checked if there is something wrong with conn.php? Also make sure your error reporting is turned on. In the first line of your root script, put this line to do that:

error_reporting(E_ALL ^ E_NOTICE);

conn.php is right coz line 8 can display.

Aaaah I think I understand what the problem is now. I thought nothing was displaying at all :). Try this if you will:

require("conn.php");
$sql = "select * from pemohon where kp_baru='$kp';";
$result = mysql_query($sql);

$has_results = false; // To be validated below.

while($row = mysql_fetch_array($result))
{
    // If the loop can be executed at least once, it means that results have been found.
    $has_results = true;

    // Display the row.
    echo $row['kp_baru'];
}

if(!$has_results)
{
    // The while loop has never been executed. No results were found.
    echo "No KP tiada didalam pangkalan data.";
}

yeah.. u are right... tq dear..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.