How to modify HTML inside PHP by CSS [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
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 '<img src="tran.png"/>';
}
}
?>
</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.

HTML have a tag called Break :) you should echo this :
echo "welcome ". $row["name"];
echo "<br />";
echo '<img src="tran.png"/>';

you need a line break
echo "welcome ". $row["name"] . '<br/>';
echo '<img src="tran.png"/>';
or
echo '</p>' . "welcome ". $row["name"] . '</p>';
echo '<img src="tran.png"/>';

<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><img src="tran.png"/></p>';
}
Or adding a <br/> like suggested #Noor Adnan

<?php
//here you can add php
?>
<p>welcome <?php echo $row["name"]; ?> </p>
<br />
<img src="tran.png"/>
<?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.

Related

Is it posible to use CSS in this way in PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to use CSS within PHP code but it seems that I can't use CSS in the way that I'm trying. why?
<?php
$username = "Daved";
$password = "hello!";
?>
<html>
<head>
</head>
<body>
<?php
echo "<div style="font-size: 32px; background-color:#f00; color:#fff; width:200px;">And Operation</div>";
if($username == "Daved" && $password == "hello!"){
echo "<p>The Password and UserName are correct!</p>";
}
else {
echo "<p>You are not a member!</p>";
}
?>
</body>
</html>
Ok, It's a true way to use CSS like this, or I must to try using style in another way?
Actual Problem is your echo statement. It should be noted that the echo prints whatever is in between " " or ''. Hence your statement echo "<div style="font-size: 32px; background-color:#f00; color:#fff; width:200px;">And Operation</div>"; is closing at style=". Hence your code is not working change it to echo "<div style='font-size: 32px; background-color:#f00; color:#fff; width:200px;'>And Operation</div>";. It will surely work.
Its possible but you made a mistake
echo "style=" font-size:32;
Php will search for the method font-size:32.
It wilp not find it and this causes an error.
Use "" to define the string and use ' ' for inline css:
echo"style='font-size:32px'";
Try this it may helps. I just modified your code little bit in the 1st echo. It just the issue of using quote operator. Thanks
<html>
<head>
</head>
<body>
<?php
echo '<div style="font-size: 32px; background-color:#f00; color:#fff; width:200px;">And Operation</div>';
if($username == "Daved" && $password == "hello!"){
echo "<p>The Password and UserName are correct!</p>";
}
else {
echo "<p>You are not a member!</p>";
}
?>
</body>
</html>

using <a href> for a mysqli select statement [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
could someone please direct me to a simple (basic easy) tutorial or resource page of how to use hyperlinks in a website to display the results of a select statement
To be precise - I am working on the footer section of my website http://www.mandyevansartist.com
when someone clicks on the words 'coloured pencils' I would like them to be taken to the catagory.php page and be shown an array from the database
I know this is possible because I already have made it work by clicking an image - (there is an area in the http://www.mandyevansartist.com/gallery.php page that says 'click on a picture to see others in that catagory')
I have achieved this by
<?php
session_start();
include 'header.php';
echo '<h1>CLICK ON AN IMAGE TO SEE OTHERS IN THAT CATAGORY</h1>';
$con = mysqli_connect("*","*","*","*");
$db = mysqli_select_db("images", $con);
$answer = mysqli_query($con,"SELECT image FROM images where HEAD = 'true'");
echo '<div id = "list">';
echo '<ul>';
while ($row = mysqli_fetch_array($answer)) {
$pic = $row[image];
$link ="<a href = 'catagory.php?id=".$row[image]."'>" . ' <img src="'.$pic.'" style ="height:222px;"/> '. "</a>";
echo '<li>' .$link.'</li>';
}
echo '</ul>';
echo '</div>';
?>
At this point my footer.php is mainly html (enclosed in an echo'') with links going to nowhere
<div id="footer-one">
<h1>GALLERY</h1>
<p><a href = "#" >people pictures</a></p>
<p><a href = "#" >romance</a></p>
<p><a href = "#" >seascapes</a></p>
<p><a href = "#" >under the ocean</a></p>
<p><a href = "#" >paintings</a></p>
<p><a href = "#" >love heart series</a></p>
<p><a href = "#" >new works</a></p>
</div><!--/footer-one-->
one of the ways I have tried to insert a mysqli query into it
<h1>GALLERY</h1>';
$answer=mysqli_query($con,"SELECT image FROM images WHERE catagory = pencils");
while ($answer2 = mysqli_fetch_array($answer));
$link = <p>family portraits</p>
echo '<p>' .$link.'</p>';
echo' <p><a href = "#" >coloured pencils</a></p>
which just comes up with a parse error - unexpected "<"
I am looking for a tutorial to guide me through this process because i have looked and looked and cant find one
The error parse error - unexpected "<" is due to some missing stuff like ', " and {}. Try following fixes.
<?php
$answer = mysqli_query($con,"SELECT image FROM images WHERE catagory = pencils");
while ($answer2 = mysqli_fetch_array($answer));
{
$img = $answer2['image'];
$link = "<a href = 'catagory.php?id=$img'>family portraits</a></p>";
}
echo '<p>'.$link.'</p>';
echo '<p><a href = "#" >coloured pencils</a></p>';
?>
From the given code, I have come up with these fixes. But there may be some changes as per your requirements.

php - How do I add div in a php function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to add a <div> to my php, but everything I've found on google hasn't worked for me. I don't know what I'm doing wrong. Any ideas on how to add a <div> in a php function for styling purposes only?
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
$buffered = ob_get_clean();
echo $buffered;
$times = $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>
You need to echo it.
Like you've already used once in your code, echo '<img src="'.$imgurl.'" />';
Now coming back to your code:
<?php
//get_additional is a custom function
ob_start();
echo get_additional('Cosmos','Trades');
echo nl2br("\n");
//I want the div to start here
echo '<div class = "blah">
// whatever you want to do here
</div>';
$buffered = ob_get_clean();
echo $buffered;
$imgurl = 'Images/cat.png';
for($i=0;$i<$times;$i++){
echo '<img src="'.$imgurl.'" />';
}
?>

PHP: how to add image? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The simplest question but I can't get it working... What's wrong with the way I'm trying to add an image to this php file?
<?php header("HTTP/1.0 404 Not Found"); ?>
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<h1 class="error"><?php echo t('Page Not Found')?></h1>
<?php echo t('We could not find a page at this address.')?>
<?php if (is_object($c)) { ?>
<br/><br/>
<?php $a = new Area("Main"); $a->display($c); ?>
<?php } ?>
<?php
echo "<img src="img.jpg">"
?>
<?php echo t('Back to Home')?>.
The file named img.jpg sits in the same directory as this .php file. When it runs, I see this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in line 21 where line 21 is echo "<img src="img.jpg">".
instead of :
echo "<img src="img.jpg">";
you can do:
echo "<img src='img.jpg'>";
or
echo '<img src="img.jpg">';
or even escape the quote:
echo "<img src=\"img.jpg\">";
Two, or possibly three, things are wrong with the way you're adding an image.
You need to use different kinds of quotation marks (" vs '), otherwise they cancel each other out.
You need a ; to end the line in PHP
Your image path may be broken. If img.jpg is not in the same directory as the PHP script, it won't work.
Replace:
"<img src="img.jpg"/>"
with
"<img src='img.jpg'/>";
If the problem is with your image path, try using an absolute path (src="http://example.com/your/path/img.jpg") instead of the relative path (src="img.jpg"). If that works, then it means that the relative path was wrong.
You have a wrong quotation on the img line and then I suggest keeping it all in PHP. You can replace your code with this code which is more easy to read and maintain:
header("HTTP/1.0 404 Not Found");
defined('C5_EXECUTE') or die("Access Denied.");
echo '<h1 class="error">'. t('Page Not Found') .'</h1>';
echo t('We could not find a page at this address.');
if (is_object($c)) {
echo '<br /><br />';
$a = new Area("Main");
$a->display($c);
}
echo "<img src='img.jpg'>";
echo ''. t('Back to Home') .'.';

echo inside an echo - does it work? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
It's been a long time since I have done php so sorry for the silly question.
This is my current code, I'm trying to save the URL as a variable so that I can insert it into the echo, but it doesn't seem to work as nothing appears:
<?php ob_start();
echo get_post_meta($post->ID, 'oldurl', true);
$old_url = ob_get_contents();
ob_end_clean();
?>
<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
I have echoed $old_url and can see that it has the correct value, but how do I insert the value into the echo do_shortcode with url="$old_url"?
This doesn't work either:
<?php echo do_shortcode('[fbcomments][fbcomments url="echo $old_url;" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
You'll need to switch your quotes around. Single quotes print everything out as-is. Double-quotes will process the variables. Also, echo is not needed within an echo.
<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>
Another way to do it without switching your quotes is to break out of the statement:
<?php echo do_shortcode('[fbcomments][fbcomments url="'.$old_url.'" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Variables are not replaced in single quotes ...
<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Singles quotes doesn't allow variables parsing.
For example :
$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"
So you have to use double quotes or use the concatenate operator : .

Categories