I have a question about an optical problem I have with php. I'm echoing a filename with this function:
echo $name."<a href='download.php?dow=$path'>Download</a><br>";
The download link appears directly behind the file name like this test.txtDownload. How do I add spaces there or how is it possible to put the download link into the 'next column' so there are listed correctly among themselves?
you can play around this:
<?php echo $name."<a class='link' href='download.php?dow=$path'>Download</a><br>";
?>
style:
<style type="text/css">
a.link {
margin-left: 10px;
}
</style>
or simply :
<?php echo $name." <a class='link' href='download.php?dow=$path'>Download</a><br>"; ?>
But I would suggest you to use css so that it can be managed, while normal space will not.
Just add a blank space in your string:
echo $name." <a href='download.php?dow=$path'>Download</a><br>";
Another option would be use some css to set the appropriate space between link name and button
Try this
echo $name." "."<a href='download.php?dow=$path'>Download</a><br>";
use the following code. Download link appears in down
echo $name.<br>.<a href='download.php?dow=$path'>Download</a><br>
instead of adding space use   instead of <br> tag.It will give you one tab space.
Related
I have created a custom wordpress post type everything works but my client asked me to insert a function that doenst show the button if the link field is empty that is also working but when I want to display the tekst or link the part where the php is inserted just doesnt shows up what am I doing wrong
I am able to get the data on other parts of this php file but not in this part of the page
<?php
$linktitle = $day_aray=get_field("under_shoe_button_title");
$linkexist = get_field("under_shoe_button_link");
echo($linktitle);
if (empty($linkexist)) {
echo '<html> <p></p></html>' ;
}
else {
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html> <?php echo($linktitle); ?> <html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
}
?>
If you would look carefully, you would notice, that you are echoing a string where, inside the string, you are trying to echo again. Even with little programming knowledge, you should understand, that it is not logical to do that.
The same goes for php opening <?php tag. You opened the tag at start of the page and later on, inside a string, you are trying to open it again. This does not work.
Instead, close the string (or escape it) and then add the echo option.
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html>';
echo($linktitle);
echo '<html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
And please, read the comments to you question and learn basic HTML
There are so many things wrong in your code
Firstly you are using echo inside echo you should use concatenation instead.
so you want to echo it like this
echo '<your html code>'.$linktitle.'<your other html code>';
Also your html code is wrong coz u are using many html tags.
I'm trying to format a PHP value from my script with a CSS style so it look the same then my html text preceding it.
Here is my code:
<p>Your surname is: </p><?php echo "<div id='php'>" $surname; "</div>" ?>
what i'd like to get is
Your name is Remi
all formatted the same way, what I get now is just an error and my PHP page does not show at all.
You have to use . (a dot) to concatenate your strings:
<p>Your surname is: <?php echo "<span id='php'>" . $surname . "</span>"; ?></p>
edit: you should use a span tag, not a div, to enhance your php output.
Your error is that you have a space between your string literal and your variable.
There is no need to echo the div tags from PHP, so don't.
You also shouldn't echo out raw text into the page, convert it to HTML first.
<p>Your surname is: </p>
<div id='php'><?php echo htmlspecialchars($surname); ?></div>
<p>Your surname is: <span id="php"><?php echo $surname; ?></span></p>
You could also go for the shorter notation:
<p>Your surname is: </p>
<div id='php'><?= $surname ?></div>
The semi-colon ends the statement. So PHP thinks that "</div>" after the semicolon is another PHP command. That causes an error and prevents the page from appearing. Move the semicolon so it's just before the ?>, and it should work.
Someone correct me if I'm wrong: Using a might cause some layout issues. I don't believe that "Your surname is" and the $surname value will appear on the same line.
I am trying to style a sentence within php by trying to echo the div. However the styling is not being applied. The css is correct, I think I have something wrong on how I am calling a div withing php. Can you please advise.
This what I have tried:
echo '<div id="sumtitle">' . "<tr><td>" . "This is a test" . "</td></tr>" . '</div>';
tried also like this:
echo '<div id="test">Test sentence</div>';
thanks
PHP is not responsible for styling.
You have to check your styles file or whatever.
Check your HTML and CSS.
PHP has nothing to do here.
The code looks OK, although the multiple use of the . in the first is unnecessary. You could just put:
echo '<div id="sumtitle"><tr><td>This is a test</td></tr></div>';
BTW: Are you using a <table> for your <tr> and <td>?
Regardless, the styling should work fine if you use something like:
#sumtitle { font-style: italic; }
or
#test {...}
I'd double check the CSS! :)
I am having trouble creating a solution that will target the end row of a MySQL query. Currently I have a foreach function that works through the query and displays each one as a div with the information inside:
<?php $residents = Resident::find_all();
foreach($residents as $resident): ?>
<div class="submenu">
<p class="menuitem submenuheader"><?php echo $resident->name; ?></p>
<img src="images/<?php echo $resident->image_path(); ?>" width="250" class="image" />
<p><?php echo $resident->info; ?></p>
</div>
.submenu currently has a bottom border. I need to remove this on the last row returned. I have looked at DESC LIMIT 1, however this requires another MySQL query and could make things very messy...
Addd this to your CSS:
.submenu:last-child { border-bottom: 0; }
Note: this is not supported by IE < 9.
You could switch to putting the border on the top of the element, and use the :first-child pseudo selector in CSS to remove it.
http://reference.sitepoint.com/css/pseudoclass-firstchild
The :last-child selector would be nice, but it's not supported in IE before version 9, so it's not a good idea to use it if you want compatibility.
If you separate your HTML and PHP a little this is easily achieved:
<?php
function echoBlock($resident,$pClass="menuitem submenuheader") {
echo "<div class=\"submenu\">\n<p class=\"$pClass\">\n";
echo $resident->name;
echo "</p>\n<img src=\"images/";
echo $resident->image_path();
echo "\" width=\"250\" class=\"image\" />\n<p>";
echo $resident->info;
echo "</p>\n</div>\n\n";
}
$residents = Resident::find_all();
$last=count($residents)-1;//2 element array last pos is 1
for ($i=0;$i<$last;$i++) {
echoBlock($residents[$i]);
}
echoBlock($residents[$last],"menuitem");
?>
echoBlock (which could easily be a method on a class) requires the calling code to know about the classes it uses, which isn't really separating intent but it does prevent the need for an if branch on every loop. That being said it would be less efficient but perhaps more usable to set it up as:
function echoBlock($resident,$isLast=false) {
$pClass="menuitem".($isLast?"":" submenuheader");
//...
Which then doesn't need the caller to know anything about what echoBlock does.
You could try and pop the array using array_pop(), to get the last value out of the array and then inputing it using the special class after the foreach loop.
What about
Instead of echo'ing each line one by one, create one big string in PHP, search for the last entry of "submenu" and change the class.
I am building a picture gallery, that uses this code to display each product I have:
<div class="feature">
<imagetag alt="Image Caption"srcs="">
<div>
<p>
This is some information that can go along with an image.
Anything can be placed here, including images.
</p>
</div>
</div>
I need to create a while loop, that takes all the products in my database, and creates a div of the "feature" class for every instance. I have problems know exactly which symbols need to be escaped and etc. Your help is greatly appreciated.
here is my start:
<?php
($product_set = mysql_fetch_assoc($query)) {
print("<div class="feature"> <imagetage alt="Image Caption" srcs=$product_set[products_image]>"
);}
?>
If you are in a string, every doublequote should be escaped. Because it will close your string.
<?php
($product_set = mysql_fetch_assoc($query))
{
print "<div class=\"feature\"><img alt=\"Image Caption\" src=" . $product_set['products_image'] . ">";
}
?>
Fun thing is, I got a link from someone on stackOverflow about PHP templating. Which was using Smarty. So you don't have to use these print states anymore.
Have you tried:
print(htmlentities($my_html_string))
or htmlspecialchars? htmlentities converts all characters that have one to their HTML escape sequence, while htmlspecialchars converts only those that have meaning in HTML.