0

This is my PHP coding from which I am grabbing data from my DB with a select where statement and outputting it. I am trying to change the text properties such as font, colour and size on the print statement can anybody assis with how to do this?

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        print " - Name: " . $row["fname"]. " " . $row["sname"]. "<br>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>

4 Answers4

2

You can style lists using HTML <ul> and <li> elements.

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>Stylists</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    echo "<ul>";

    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<li>Name: " . $row["fname"]. " " . $row["sname"]. "</li>";
    }
    echo "</ul>";
} else {
    echo "0 results";
}

mysqli_close($conn);
?></body>
</html>

And in css/style.css put something like this:

li {
   color: red;
   font-weight: bold;
   font-size: 12pt;
}

You can also put the style inline in the head section:

<style type="text/css">
li {
   color: red;
   font-weight: bold;
   font-size: 12pt;
}
</style>
Adder
  • 5,708
  • 1
  • 28
  • 56
  • Yes I already have a CSS directory created under default.css with all my CSS styles within it and I added the
  • style to it yet no joy
  • – shaminder galla Mar 09 '18 at 10:12
  • Do the balls in front of every line show up for the code `echo "
  • Name: " . $row["fname"]. " " . $row["sname"]. "
  • ";`? Can you show your css? Also do a shift-click reload to purge the cache of old copies of your css file. – Adder Mar 09 '18 at 10:16