Trotterwatch
Trotterwatch

Reputation: 43

Displaying a PHP result

I am trying to learn php together with MYSQL. I have built the database on on the from end I have written the code below to bring in the website title from the database which works. However, I have two questions.

  1. How would I get the result to display in <h1> tags?
  2. Is this the cleanest way of pulling this value through?

Any help or advise greatly appreciated

<?php
include 'connection.php';

$sql = "SELECT VariableValue FROM VariableValues WHERE VariableID = '1'";
$result = $conn->query($sql);

while($header = $result->fetch_assoc()) {
    echo $header["VariableValue"].  "<br>";
}

?> 

Upvotes: 1

Views: 77

Answers (3)

Kshitij Pandey
Kshitij Pandey

Reputation: 114

You can echo all types of tags in PHP echo for example:

echo '<div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
          <div id="success_alert" align="center" class="alert alert-success">
              <strong>Log in to download this chapter.</strong>
          </div>
      </div>';

I have echoed different types of bootstrap tags in echo. Similarly you can also echo all types of tags you want.

Upvotes: 0

Ani Menon
Ani Menon

Reputation: 28199

To get a single row from db, you could use this:

$header_title = implode(mysqli_fetch_assoc(mysqli_query($conn, "SELECT VariableValue FROM VariableValues WHERE id = 1 LIMIT 1")));

Put a php variable between a html tag :

<tag><?php echo $var; ?></tag>

Eg :

<title><?php echo $header_title; ?></title>

Upvotes: 1

Jobel
Jobel

Reputation: 236

To displays it in tags, use <h1><?php echo $var; ?></h1> for example.

Upvotes: 0

Related Questions