Web Hosting Talk







View Full Version : Help Related to PHP+SQL


jainritesh
07-18-2009, 07:31 AM
Hello All,

I'm using following code on my website to retreive Plan Details.

<?php
$SQL = "SELECT * from PLANS WHERE ID = '$_GET[id]'"; $result = @mysql_query( $SQL ); $row = @mysql_fetch_array( $result );
$description = preg_replace("/\n/","\n<BR>",$row[DESCRIPTION]);
$summary = preg_replace("/\n/","\n<BR>",$row[SUMMARY]);
?>

If the output is null or entry not present in the database how to display the same. (I want to display this message if the same is not there --> Plan Not found)

Please Help,

Best Regards,
Ritesh Jain

Krupux
07-18-2009, 10:28 AM
<?php
$SQL = "SELECT * from PLANS WHERE ID = '$_GET[id]'";
$result = @mysql_query( $SQL );
$row = @mysql_fetch_array( $result );

if($row === false)
{
// Process the "Plan Not Found"
$description = "Plan not found";
$summary = "-";
}
else
{
$description = preg_replace("/\n/","\n<BR>",$row[DESCRIPTION]);
$summary = preg_replace("/\n/","\n<BR>",$row[SUMMARY]);
}


Also, you can use PHP's nl2br() to replace "\n" to "<br />".

jainritesh
07-19-2009, 04:07 AM
thanks for the quick help.
Also Is it possible to customize font size, color etc.

Regards,
Ritesh Jain

HivelocityDD
07-19-2009, 06:40 PM
if(empty($row)) {
$description = "Plan not found";
} else { $description = "Your expression"; }



Yes ! You can set the style there

like

$description = "<div style='Your style of font and size goes here'> Plan not found</div>";