Bootstrap FreeKB - PHP - Banner messages
PHP - Banner messages

Updated:   |  PHP articles

Let's say you want to display a banner on your website when a certain event occurs. For example, if there is some outage, you want to present a message to your visitors letting them know an outage is occurring.

Create a table in SQL with the following columns:

  • banner
  • message1
  • message2
  • message3

Add this PHP to the Web page where you want the banner to display.

When you want to display the banner, set banner to "true" in SQL, and type the message you want displayed. When you no longer need the banner to appear, set banner to "false" in SQL.

<?php 
$serverName = "example";
$connectionInfo = array( "Database"=>"example", "UID"=>"example", "PWD"=>"example");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$banner = "select * from banner";
$banner_query = sqlsrv_query( $conn, $banner );
while( $row = sqlsrv_fetch_array( $banner_query, SQLSRV_FETCH_ASSOC)) {		
	$banner = $row['banner'];
}

if ($banner == "true") {
	$banner = "select * from banner";
	$banner_query = sqlsrv_query( $conn, $banner );
	while( $row = sqlsrv_fetch_array( $banner_query, SQLSRV_FETCH_ASSOC)) {
		echo "<div style='border: 1px solid black; padding-top: 15px, padding-bottom: 15px; text-align: center; font-size: 14pt; color: white; background-color: black;'>";
		echo "<font color='red'>"; echo $row['message1']; echo "</font><br />";
		echo $row['message2']; echo "<br />";
		echo $row['message3'];	
		echo "</div>";
	}
}	
?>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5c04b9 in the box below so that we can be sure you are a human.