is there something wrong from with my code? something hidden quote i forgot to close.
{
echo '<div class="project_box" title="'. $row['title']. '">';
echo '<p class="project_title">' . $row['title'] . '</p>';
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
echo '</div>';
}
when i echo this in my project box it has some space between the bottom of the image, and the bottom border i give to the div. i give the box a height "auto".
this is the div i place the echo'ed stuff in;
.project_box{
float:left;
width: 200px;
height: auto;
border: 1px solid #dbae78;
opacity: 0.7;
}
i cant find the problem:( i hope you see the problem in my code what i didn't see atm.
i want the border sticks to the bottom of the image.
It looks like
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200"</img>';
Should be
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['image']) . '" width="200" height="200" />';
The img tag is a self closing tag, meaning it won't have a <img> and a </img>, only a <img/>. Also, even if it did, you still didn't have the closing bracket on the beginning of the tag.
Related
In my code, I have a center tag and have styled the center tag so it looks the way I want it to look. It currently looks like this:
Whenever I go on my admin account (one that has a different user id than the normal users) it looks way different than if a regular user would see it. It looks like this:
I would like to know if there is any way around this so it looks the same as if a regular would see it on an admin account.
I've tried putting a div tag around it and using the same styling features, but that didn't work. I've tried putting the center tag around different parts of the code, but since it's an "if" statement, it will look different.
Here is the code:
<style>
center{
border-left: .17em dashed;
border-top: .17em solid;
border-right: .17em dashed;
border-bottom: .17em solid;
padding-left:25px;
padding-bottom: 20px;
width: 1000px;
background-color: #E1A0A0;
border-color: black;
margin: auto;
text-align: left;
}
</style>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments | ';
if($_SESSION['user_id'] == 3) {
echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a></center>';
}
}
?>
I know that I can't just put another center tag around the
"echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments |';"
part of the code and
"echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a></center>';"
part of the code because it will look like this:
Additionally, if I put the center tag around everything, it will look like this:
I just want to make it look the same no matter who views it.
after the close of the if(){} you need to echo '</center>' and remove it from inside the if(){}. You have setup a loop where sometimes center is not closed
echo '<center><b><h2>' . $row['title'] . '</h2></b>' . $row['post'] . '<br/><br/> <b>Posted On: </b>' . $row['postdate'] . '<br/>View Post Comments | ';
if($_SESSION['user_id'] == 3) {
echo '<a href="update.php?id=' . $row['blogid'] . '" >Update Blog Post</a> | <a href="' . basename(__FILE__) . '?id=' . $row['blogid'] . '" >Delete Blog Post</a>';
}
echo '</center>';
Not sure if I quite understand what is being asked for, but if all you want to do is make everything look like the last image you posted, remove this in the css:
padding-left:25px;
I am using the php code below to echo an image from mysql database, please help me show how can I set the width and height of the image?
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
This has nothing to do with SQL, it's a matter of CSS.
The CSS rules you need are width and height, and you can specify them either in the tag itself
echo '<img style="width: x; height: y" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
or in a style tag in your header section
echo '<style type="text/css">
#venue{
width: x;
height: y;
}
</style>'
...
echo '<img id="venue" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
or even in a separate file
yourStyle.css
#venue{
width: x;
height: y;
}
yourPHPfile.php
echo '<link rel="stylesheet" type="text/css" href="yourStyle.css" />';
...
echo '<img id="venue" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
You can read more about how CSS works and the different places it can be placed here (and in many other places, you can just search "CSS where").
There are multiple ways to do this, on simple solution is to echo the image with proper styling, something like this
echo '<img style="width: 500px; height: 200px" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
Another solution is to add a class or an ID to your image and then create a CSS rule to style it
echo '<img id="foo" src="data:image/jpeg;base64,' . base64_encode($row['venueimage']) . '"/>';
And in your CSS
#foo{
width: 500px;
height: 200px;
}
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href=' . <?php grab_item_image(); ?> . "</div>"';
break;
}
}
That was my attempt but it does not look rite on my text editor. I am also using inline-css not sure if that matters.
The only thing that i'm trying to echo out is this div with the function providing an href.
<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href="#thephpfunctionhere"</div>
It's kind of confusing me with all the single and double quotes.
Quotes Problem and you started <?php again. Use the code below
//top of the code just consists of an if statement and some code.
case 'itemimage' :
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . grab_item_image() . '" /></div>"';
break;
}
}
Hope this helps you
echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . <?php grab_item_image(); ?> . '"></div>"';
The image needs the ''SRC'' attribute instead of href. Also, since you are echo-ing within a php-tag you don't have to open the <\?php again but directly refer to the function.
echo
'<div class="product-preview-image" style="background: red; height:75px; width:75px;">' ,
'<img src="' . grab_item_image() . '" />' ,
'</div>"';
Komma's are even faster when using a direct echo. Not suitable for assigning it to a $variable
I have the following syntax:
echo "<img src=\"images2/" . $row['image'] . "\" alt=\"\" /><br />"; }
I would like to a give a specific height and width for the image, but I can't to do it.
You can specify dimensions directly in your HTML <img> tag:
echo "<img src=\"images2/\" . $row['image'] . "\" alt=\"\" height=\"100\" width=\"100\" /><br />";
Note that your posted code has a closing curly brace (}) following your echo statement, which will cause a PHP error if there's no corresponding opening curly brace. You're also incorrectly escaping the double-quotes after images2/, which will result in invalid markup.
A better approach would be to enclose your entire markup in single quotes so that you don't have to escape the double quotes enclosed within:
echo '<img src="images2/' . $row['image'] . '" alt="" height="100" width="100" /><br />';
EDIT:
For modern day markup (depending on your requirements), it's considered vastly preferable to modify image dimensions in CSS, rather than in your <img> tag. You may want to consider implementing something akin to the following:
<style type="text/css">
img {
width: 100px;
height: 100px;
}
img.large {
width: 200px;
height: 200px;
}
</style>
<?php
echo '<img src="images2/' . $row['image'] . '" alt="" /><br />'; // no class attribute, so will default to 100x100
echo '<img src="images2/' . $row['image'] . '" alt="" class="large" /><br />'; // class attribute is `large`, so will rescale to 200x200
This should work
echo '<img src="images2"'.$row['image'].'\ alt="" width="" height="" /><br />'; }
I am trying to figure out why I'm getting this error
"Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/idgcca/public_html/web-design-samples-testing.php on line 64"
echo '
<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title='<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>';" onmouseout="this.title='';" href="'. $post->url . '">
<img src="' . $post->thumb . '" border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div>
';
im a PHP newb just trying to understand it on my own but my head is turning. A help would be pretty much appreciated...
here is your problem:
this.title='<
you should escape this quote. and the one at the closing a tag too. like this:
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]" title="'. $post->title .'"
onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';"
onmouseout="this.title=\'\';" href="'. $post->url . '">
<img src="' . $post->thumb . '" border="0"/></a>
<div class="design-sample-txt">'. $post->author.'</div>
</div>';
You have an unterminated string on that line. You should escape your quotes with a slash like this \"
echo "<div style=**\"**float:left;.....";
You need to escape single-quotes in a single-quote-string.
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';" onmouseout="this.title=\'\';" href="'. $post->url . '">';
I would advise you to split your code in multiple lines for readability.
It'll help to debug this kind of line.
Take a look at the echo operator examples
To answer to your question, there are some quotes misused in your code. You need to escape them.
echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a
target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';"
onmouseout="this.title=\'\';" href="'. $post->url . '"><img src="' . $post->thumb . '"
border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div>';
Assuming you pasted the code exactly, the first error is right at the beginning, when you end the first quote. It expects that to read:
echo ' title .';
The two quotes next to each other don't make any sense.
You got your answer from SilentGhost.
I would use HEREDOC for such things.
You should use htmlspecialchars on those attribute values:
function html($str, $charset=null) {
if (!is_null($charset)) {
return htmlspecialchars($str, ENT_QUOTES, $charset);
} else {
return htmlspecialchars($str, ENT_QUOTES);
}
}
echo '
<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;">
<a rel="lightbox[web]"
title="' . html($post->title) . '"
onmousedown="' . html('this.title=\'<a target="_blank" href="http://www.google.ca/">Google</a>\'') . '"
onmouseout="' . html('this.title=""') . '"
href="' . html($post->url) . '">
<img src="' . html($post->thumb) . '" border="0"/></a>
<div class="design-sample-txt">' . html($post->author) . '</div>
</div>
';