I know this has already been put out on here but I've looked and mine still won't work and I don't know why someone please give me a hand.
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50); . '"/>';
Remove the semicolon you have after resize
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50) . '"/>';
Try this
echo "<img src= '".Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50)."'/>";
Please change
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50); . '"/>';
this line to
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50) . '"/>';
Because you had put one extra semi column ; after the resize(50,50)
Please change your code and try. Definitely work .
Related
I'm trying to get this so when I click the image, the image then shows in a new tab so it's able to be saved
I've tried adding the a href tags inside and around.
Code:
echo "<img src=" . random_image('css/avatars') . " />";
This is what you want:
echo '<img src="' . random_image('css/avatars') . '" />';
You should try
echo "<a target='_blank' href='".random_image('css/avatars')."'>"."<img src=" . random_image('css/avatars') . " /></a>";
I think this can help you
The problem is that you are not properly concatenating your string with what you get from random_image function.
You can try following code, here I am assuming that your random_image function returns complete path to your image
function random_image($path)
{
// returning dummmy image
return "https://images.unsplash.com/photo-1535498730771-e735b998cd64?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=623ed05afcc5a3fa1e444ffca95854dc&w=1000&q=80";
}
echo "<a href='".random_image('css/avatars')."' target='_blank'> <img src='".random_image('css/avatars')."' /></a>";
I am aware that I cannot use an echo inside an echo. My php code is:
echo '<img src="img/image1.jpg"
I want to use php variable as the source. Somethink like:
echo '<img src="php-code"
Using .(dot) you can concatenate php variable in echo statement.
echo '<img src="'.$src.'" />';
You have four options:
$url = '...';
//1
echo '<img src="' . $url . '">';
//2
echo "<img src='{$url}'>"; //Note that you have to use double quotes
//3
echo '<img src="';
echo $url;
echo '">';
//4
echo '<img src="', $url, '">'; //I would not recommend this one though
just skip first echo and write the html with an echo in the middle
<img src="<?=$src?>">
All of these works
echo '<img src="', $url, '">'; # This works by sending 3 different parameters to echo
echo '<img src="' . $url . '">'; # This works by concatenating 3 strings before echoing
echo '<img src="'; echo $url; echo '">'; # This works by echoing 3 strings in turn
echo "<img src=\"$url\">"; # All of these works by inserting
echo "<img src=\"${url}\">"; # the value of $url in the string
echo "<img src=\"{$url}\">"; # before echoing. " needs to be escaped.
# And finally, this (called HEREDOC) does the same thing as above
# only without ", so that sign is not needed to be escaped
echo <<<FOO
<img src="$url">
<img src="{$url}">
<img src="${url}">
FOO;
There are many solutions.
I prefer this one: <?php echo '<img src="'.$url.'">'; ?>
$url stands for the Image-Url, I guess you know ist.
You can do it also:
For example: <img src="<?php echo $url; ?>">
But I like the first method, it's a simple way to put out strings.
My code in php is
echo $preference[0]."</br>";
echo '<p class="filter_entity">'.$preference[0].'<img src="' . base_url() . 'images/close-icon.png" onClick="filter_close()"></p>';
html out put is
Business
<img onclick="filter_close()" src="http://localhost/AEC/images/close-icon.png">
I want to put $preference[0] in filter_close() of my php code ... dont know how to do it .
Something like this?
$param = $preference[0];
echo '<p class="filter_entity">'.$preference[0].'<img src="' . base_url() . 'images/close-icon.png" onClick="filter_close(\''.echo $param.'\')"></p>';
Just append the variable as a parameter of the js function
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double
echo "Some array item: {$array[0]}";
can anyone tell my why this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='../images/producten/monster_energy_green.png' alt='' /></a>";
does give a clickable image link, and this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt'productafbeelding' /></a>";
doesnt? (not clickable).
thanks in advance!!
php rookie..
In the first one you have a real scr it's directing to with a file extension. the second does not. If the second is supposed to be picking up a variable we would need more information
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt='productafbeelding' /></a>";
just add a "=" between alt and 'productafbeelding'
Try this one:
echo '<img src="' . $rij['afbeelding_klein'] . '" alt="productafbeelding" />';
Screenshot of the code:
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
require ('../../mysqli_oop_connect.php'); //Connect to the database.
$errors = array(); // Initialize an error array.
// Check for an isbn:
if (empty($_GET['isbn'])) {
$errors[] = 'You forgot to enter the ISBN-13.';
} else {
$isbn = $mysqli->real_escape_string(trim($_GET['isbn']));
}
if (empty($errors)) {
//Make the query:
$q = "SELECT * FROM books WHERE isbn=$isbn";
$r = $mysqli->query($q);
$num = $r->num_rows;
if ($num == 0) { // If it fails to run:
echo "<br /><br /><p>This book is currently not listed in our database. Would you like to add it?</p>\n";
//HERE IS WHERE IT NEEDS TO REDIRECT TO A PAGE THAT ALLOWS THE CONTENT TO BE ADDED TO THE DB LIKE REGISTER.PHP DOES.
} else { //If it suceeds then run the query:
echo '<h1>Is this your book?</h1>';
while ($row = $r->fetch_object()) { // POST DATA FROM DB.
echo '<img src="$row->image" height="100" width="100">' . '<br />' . $row->name . '<br />' . $row->isbn ;
The rest of the code is just closing the DB connection.
I don't know what that icon means or where the issue is in the code. The DB is setup with three columns in a table: image, isbn, and name. The goal is to get the book to display the data being retrieved from the database. It is displaying all three items from the database based on the query, except the image is something else. The HTML is recognizing that there is an image being retrieved because when I just do $row->image it freaks out and posts random nonsense, as it should when there is an image being displayed like that. Any help is greatly appreciated.
echo '<img src="'.$row->image.'" height="100" width="100"><br />' . $row->name . '<br />' . $row->isbn ;
Try this way, and better you print your image path and check if it does exist or does not exist, and yes you can also inspect image element and check path of the image.
Its not clear in the question whether there is image link saved in the db or image data in base64. Answer is given assuming db has image link.
I'd guess from your comments about 'freaks out and posts random nonsense' that your image is stored in your database, rather than the path to your image. If so, you can't simply echo the image data in your <img> tag. The src attribute requires a URL, which you can create in one of two ways: create a script that serves the image with appropriate headers and use the URL of that script as your src attribute; or, create a data URI and include the data in your page. The latter is probably the simplest, but could increase the load time of your pages. Here's how:
// base64 encode image data and prepend the header
$imgURL = "data:image/png;base64,".base64_encode($row->image);
echo '<img src="'.$imgURL.'" height="100" width="100">' .
'<br />' . $row->name . '<br />' . $row->isbn ;
Note - you'll need to change the dataURL header to send the correct image type: image/jpg, image/png, etc.
You cannot have string substitution with single quotes. It will simply place the text $row->image in the echo:
echo '<img src="$row->image" height="100" width="100">' . '<br />' . $row->name . '<br />' . $row->isbn ;
Try this instead:
echo "<img src='$row->image' height='100' width='100'>" . '<br />' . $row->name . '<br />' . $row->isbn ;
Or this:
echo '<img src="' . $row->image . '" height="100" width="100">' . '<br />' . $row->name . '<br />' . $row->isbn ;
Personally, I prefer using sprintf like this:
echo sprintf('<img src="%s" height="100" width="100">', $row->image) . '<br />' . $row->name . '<br />' . $row->isbn ;
But on top of that, to make your debugging life even easier, I recommend formatting your PHP code to be easier to read like this:
echo sprintf('<img src="%s" height="100" width="100">', $row->image)
. '<br />'
. $row->name
. '<br />'
. $row->isbn
;
The cleaner your code is from the beginning, the easier it is to spot flaws & bugs when they arise.