Home  >  Q&A  >  body text

How to change the appearance of paragraphs in php files

I tried making the file as an html file, or putting <link rel="stylesheet" type="text/css" href="mystyle.css"> directly, but It doesn't work. I want to be able to change the pharagraph producten font size.

This is my code so far (about the last part())

<?php
  include('DatabaseConnector.php');
  $database = new DatabaseConnector("test", "root", "");
  <link rel="stylesheet" type="text/css" href="mystyle.css">

    $email = $database->selectValue("SELECT emailadres FROM klant WHERE naam = 'Bibiche' AND achternaam = 'Laarakkers'");
      echo "Het emailadres van Bibiche Laarakkers is $email.";

    $productInfo = $database->selectSingleRow("SELECT gewicht, prijs, calorieen FROM product WHERE naam = 'Sausage Muffin with Egg Whites'");
      echo "<h2> Sausage Muffin with Egg Whites </h2>";
      echo "<p>Gewicht: " . $productInfo['gewicht'] . "<br>";
      echo "Prijs: " . $productInfo['prijs'] . "<br>";
      echo "Aantal Calorieën: " . $productInfo['calorieen'] . "</p>";

      $producten = $database->selectRows("SELECT naam, prijs FROM product");
          foreach($producten as $product) {
            echo "<p class='pruducten'> Product:" . $product['naam'] . "<br>";
          echo "Prijs:" . $product['prijs'] . "</p>";

          }
?>

P粉596191963P粉596191963287 days ago447

reply all(1)I'll reply

  • P粉726234648

    P粉7262346482024-01-30 09:38:37

    If you are trying to print a link in php code, could you try something like this and see if it works?

    The reason I use echo is that it prints out the code of the stylesheet. If I put the code directly into the middle of php without echoing it or wrapping it in '' , it won't display or print correctly.

    ';
    
        $email = $database->selectValue("SELECT emailadres FROM klant WHERE naam = 'Bibiche' AND achternaam = 'Laarakkers'");
          echo "Het emailadres van Bibiche Laarakkers is $email.";
    
        $productInfo = $database->selectSingleRow("SELECT gewicht, prijs, calorieen FROM product WHERE naam = 'Sausage Muffin with Egg Whites'");
          echo "

    Sausage Muffin with Egg Whites

    "; echo "

    Gewicht: " . $productInfo['gewicht'] . "
    "; echo "Prijs: " . $productInfo['prijs'] . "
    "; echo "Aantal Calorieën: " . $productInfo['calorieen'] . "

    "; $producten = $database->selectRows("SELECT naam, prijs FROM product"); foreach($producten as $product) { echo "

    Product:" . $product['naam'] . "
    "; echo "Prijs:" . $product['prijs'] . "

    "; } ?>

    If this doesn't work, since css links are best used within the < head > section of the document, you can print the code directly into it by echoing the code so it prints it correctly to the page. like this:

    
        .pruducten {
            font-size:1rem;
        }
        ';
        $email = $database->selectValue("SELECT emailadres FROM klant WHERE naam = 'Bibiche' AND achternaam = 'Laarakkers'");
          echo "Het emailadres van Bibiche Laarakkers is $email.";
    
        $productInfo = $database->selectSingleRow("SELECT gewicht, prijs, calorieen FROM product WHERE naam = 'Sausage Muffin with Egg Whites'");
          echo "

    Sausage Muffin with Egg Whites

    "; echo "

    Gewicht: " . $productInfo['gewicht'] . "
    "; echo "Prijs: " . $productInfo['prijs'] . "
    "; echo "Aantal Calorieën: " . $productInfo['calorieen'] . "

    "; $producten = $database->selectRows("SELECT naam, prijs FROM product"); foreach($producten as $product) { echo "

    Product:" . $product['naam'] . "
    "; echo "Prijs:" . $product['prijs'] . "

    "; } ?>

    If you absolutely must print every aspect of the page in php code, the above is how I would do it.

    There are other ways to achieve this by using html directly in the php file, such as making sure it has a < head > section etc. But I want to work along the path you're on to better help you solve your problem.

    reply
    0
  • Cancelreply