Page 1 of 1

How to add in <style> CSS php echo

Posted: 28 Oct 2021, 15:02
by JanMolendijk
Dear Coursesweb, Hope you do all fine

I can not find out how to add in the <style> a result from my database.
Hope to get some support for this. `thanks`

Code: Select all

<?php 
include('../connection1.php');

$id = (int) $_GET['id'];

$sql=mysqli_query($connmaker,"SELECT * FROM `maker` WHERE post_id='" . $id . "' ");
$users=mysqli_fetch_assoc($sql);
?>

<style>
body {
  font-family: "Exo 2", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background: <?php echo $users['bbgcolor'];?>;
  min-height: 100vh;
}
</style>

How to add in <style> CSS php echo

Posted: 29 Oct 2021, 04:52
by MarPlo
Hello,
Try the followig code:

Code: Select all

<?php 
include('../connection1.php');

$bgc_user ='green';   // default color

if(isset($_GET['id'])) $id = (int) $_GET['id'];
else $id =1;

$result= mysqli_query($connmaker, "SELECT * FROM maker WHERE post_id=". $id);
while($row = mysqli_fetch_assoc($result)){
  $bgc_user = $row['bbgcolor'];
}
?>

<style>
body {
  font-family: "Exo 2", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background: <?php echo $bgc_user; ?>;
  min-height: 100vh;
}
</style>
- If the color is in hex code, add # before it (ex.: background: #aabcfe;).

How to add in <style> CSS php echo

Posted: 29 Oct 2021, 11:32
by JanMolendijk
O GOD THANKS MARPLO

When I`m home I gonna try the code

So much thanks for this support