-7

I wrote this code

<html>
<head>
<title> page 1</title>
<body>
<style>

a{
    margin-left:10px;
}
</style>

<?php
    $con = mysqli_connect('localhost', 'root', '');
    mysqli_select_db($con,"uoh");  
    $q = " SELECT * FROM student WHERE id = 201102820" ;
    $result = mysqli_query($con , $q ) ;
    if($row = mysqli_fetch_array($result)){
        if ($row["major"]=="computer engineerig"){
               echo "welcome ". $row["name"];
               echo '<a href="tran.php?page=A"><img src="tran.png"/></a>';
        }
    }
?>
</body>
</html>

but when I run it show me like this

Welcome stephen ICON

the icon(picture) that I put comes in front of the text .

Can I do like this

welcome stephen  
ICON

I want the icon (picture) comes under the text.

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
stephen
  • 1
  • 2

4 Answers4

1

HTML have a tag called Break :) you should echo this :

echo "welcome ". $row["name"];
echo "<br />";
echo '<a href="tran.php?page=A"><img src="tran.png"/></a>';
Abu Yousef
  • 570
  • 3
  • 21
0

you need a line break

echo "welcome ". $row["name"] . '<br/>';
echo '<a href="tran.php?page=A"><img src="tran.png"/></a>';

or

echo '</p>' . "welcome ". $row["name"] . '</p>';
echo '<a href="tran.php?page=A"><img src="tran.png"/></a>';
A H Bensiali
  • 825
  • 1
  • 9
  • 22
0

<a> and <img> are inline elements by default. See this article : CSS display: inline vs inline-block

So you have to put the ICON block in a block element to see a separation between the name and the icon.

Like this for example :

    if ($row["major"]=="computer engineerig")
    {
      echo "welcome ". $row["name"];
      echo '<p><a href="tran.php?page=A"><img src="tran.png"/></a></p>';
    }

Or adding a <br/> like suggested @Noor Adnan

Community
  • 1
  • 1
Vincent G
  • 8,547
  • 1
  • 18
  • 36
0
<?php
        //here you can add php 
?>
<p>welcome <?php echo $row["name"]; ?> </p>
<br />
<a href="tran.php?page=A"><img src="tran.png"/></a>
<?php 
          // here you can add your php
?>

If you Separate your HTML and PHP then you can easily add css and HTML inside your PHP.

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42