I have this:
<?php echo $this->htmlLink($this->viewer()->getHref(), $this->itemPhoto($this->viewer(), 'thumb.icon')); ?>
That generates an HTML code like:
<a href="http://www.domain.com/john">
<img src="http://www.domain.com/thumb_0205.jpg" alt="" class="thumb_icon item_photo_user thumb_icon">
</a>
Now, what I am trying to do, is to add:
<?php echo $this->viewer()->getTitle(); ?> //This will generate the member's name, like "John Doe"
to the code above, to generate an HTML code like:
<a href="http://www.domain.com/john">
<img src="http://www.domain.com/thumb_0205.jpg" alt="" class="thumb_icon item_photo_user thumb_icon">
<span>John Doe</span>
</a>
Anyway I can do that?
Thanks
This ought to work:
<?php echo $this->htmlLink(
$this->viewer()->getHref(),
$this->itemPhoto($this->viewer(), 'thumb.icon') . '<span>' . $this->viewer()->getTitle() . '</span>'
); ?>
Guessing, this should work:
<?php echo $this->htmlLink($this->viewer()->getHref(), $this->itemPhoto($this->viewer(), 'thumb.icon').'<span>'. $this->viewer()->getTitle().'</span>'); ?>
Just append the extra string to the second argument of htmlLink.
HtmlLink($href, $text, $title = "", array $attribs = array());
Related
When I run the following file I get the database data i.e it prints it out on the website so I know my connections are good.
<html>
<?php include 'config.php'?>
<?php include 'header.php'?>
<?php
$sql = "SELECT name, image FROM images";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo $row["name"], $row["image"];
}
?>
</div>
</html>
However when I try and format the results like below
<html>
<?php include 'config.php'?>
<?php include 'header.php'?>
<?php
$sql = "SELECT name, image FROM images";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo <div id = "bookbar">
<img src= "$row['image']" alt = "image">
<p> $row['name'] </p>
</div>
}
?>
</div>
</html>
it doesn't work. Can anyone help me fix the code?
Maybe try this your code didn't close/open the php tags properly also don't echo like that
<?php include 'config.php'?>
<?php include 'header.php'?>
<?php
$sql = "SELECT name, image FROM images";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<div id = "bookbar">
<img src= "<?php echo $row['image'] ?>" alt = "image">
<p><?php echo $row['name']; ?></p>
</div>
<?php
}
}
$conn->close();
?>
If you want to echo something out
Its better to close on open the php tags like so
PHP goes here
?>
HTML goes here
<?php
PHP goes here
And if you want to echo something inside the HTML just do this
<span> <?php echo "something" ?> </span>
much easier and makes the code easier to read.
change your echo statement to -
echo '<div id = "bookbar"><img src= "' . $row['image'] . '" alt = "image"><p>'. $row['name'] .'</p>'
Your issue is a syntax problem - you can't use echo like that, it has to echo a string variable. You should be seeing an error message about it.
You could keep the echo statement and put all the HTML inside a string, and concatenate (or interpolate) the PHP data into it. But IMO the easiest thing here in terms of readability and maintenance is to step out of the PHP tags, print the HTML, embed some PHP tags in it for the variables, and then step back in again to continue with the code. It makes the HTML far easier to understand:
?>
<div id="bookbar">
<img src="<?php echo $row['image'] ?>" alt="image">
<p><?php echo $row['name'] ?></p>
</div>
<?php
When you are in php mode you should echo strings as php variables wrapped with single quotes:
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<div id = "bookbar">';
echo '<img src="' . $row['image'] . '" alt = "image">';
echo '<p>' . $row['name'] . '</p>';
echo '</div>';
}
I am trying to display images on my web page, the content is getting fetched from my database, but the issue I'm facing is in displaying the image. please, can anyone guide me how should I display the image?
I mean to say the path what I should give
here 'image' is my column name and this is my view
<?php
if( !empty($results) ) {
foreach($results as $row) {?>
<div class="col-sm-4">
<img src="<?php echo base_url('uploads/');$image?>" alt="">
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->content; ?></p>
</div>
<?php
} ?>
<?php }
?>
Hope this will help you :
Use this : <img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">
The whole code should be like this :
<?php
if( !empty($results) ) {
foreach($results as $row) {?>
<div class="col-sm-4">
<img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->content; ?></p>
</div>
<?php
} ?>
<?php }
?>
If $image is the column name(which contains image name) then Replace
<img src="<?php echo base_url('uploads/');$image?>" alt="">
with
<img src="<?php echo base_url();?>uploads/<?php echo $row->image;?>" alt="">
If $image has image path then remove ';' and add '.' on echo base_url('uploads/');$image?> line
You issue here is the following code;
<?php echo base_url('uploads/');$image?>
This is because you are not concatenating the string, rather, just saying it's variable name, so, use of the following will provide the output;
<?php echo base_url('uploads/') . $image' ?>
This replaces the semi-colon part way through for a period (.) which is the PHP concatenation operator
Obviously, there is the issue you are not setting $image, which would require (before usage) of;
$image = $row['image_column_name'];
// Or
$image = $row->img_column_name
I'm trying to modify a plugin which sends out url's in an email notification.
The code in the plugin is this
<?php the_title(); ?>: <?php the_job_permalink(); ?>
It displays the following in the email
Front End Risk Account Manager: http://tbc-recruit.com/job/front-end-risk-account-manager/
What I'd like to end up with is a url in this format
http://tbc-recruit.com/job/front-end-risk-account-manager/?utm_source=jobalerts&utm_medium=email
I have tried the following
<?php
$alerturl = the_job_permalink();
$alerturl .= "?utm_source=jobalerts&utm_medium=email";
?>
<?php the_title(); ?>:<?php echo $alerturl; ?>
That code gives the following output
Front End Risk Account Manager:?utm_source=jobalerts&utm_medium=email
Maybe because the_job_permalink() show html content like
http://tbc-recruit.com/job/front-end-risk-account-manager/
You should use get_permalink()
<?php
$alerturl = get_permalink() . '?utm_source=jobalerts&utm_medium=email';
?>
<?php the_title(); ?>:<?php echo ' ' . $alerturl . ''; ?>
I hope this helped you
Use get_the_title() instead of the_title()
I am trying to display RSS feed in my magento website and I'm having difficulties showing the image for the feed. Studying the feed, I see that the image is inside a content:encoded tag so I can't access it directly by using something like $item->image. Here's my current code:
<?php $channel = new Zend_Feed_Rss('newsfeedurl'); ?>
<?php foreach ($channel as $item): ?>
<?php if($i<2) { ?>
<img src="<?php echo $item->image; ?>" title="<?php echo $item->title; ?>" height="63" width="95" />
<?php echo "image:".$item->content; ?>
<?php } else {} ?>
<?php $i++; ?>
<?php endforeach; ?>
$?>
I tried also tried using $item->content but this returns the entire content of the newsfeed. So my question is, how can I access the image's source from content:encoded in order to display it on my feed?
UPDATE: After some more research, I tried using preg_match like so: preg_match('/<*img[^>]*src = ["\']?([^"\'])/i', $item->content, $matches); echo $matches[0]; I'm getting the correct image path but I've placed this inside a loop so each I should have at least 2 images but I'm only getting 1. why is this?
SOLVED: I've managed to solve my problem by changing $matches[0] to $matches[1]. I guess I was using 0 thinking it was the index of an array matches.
In order to get the image source from the content:encoded tag, I used regular expression (preg_match). Here's how my current code looks:
<?php $channel = new Zend_Feed_Rss('newsfeedurl'); ?>
<?php foreach ($channel as $item): ?>
<?php preg_match('/<*img[^>]*src *= *["\']?([^"\']*)/i', $item->content, $matches); ?>
<?php if($i<2) { ?>
<img src="<?php echo $matches[1]; ?>" title="<?php echo $item->title; ?>" height="63" width="95" /></a></div>
<?php } else {} ?>
<?php $i++; ?>
<?php endforeach; ?>
Hope this helps someone else.
I'm try to make some changes to my ZenPhoto installation in order so that at the bottom of an album page I have a text area which displays the "embed" code of the generated images above, so that readers can simply copy it and post the html onto their own sites.
Here is the snippet of code.
<?php $str = ''; ?>
<?php while (next_image()): ?>
<div class="imagethumb"><?php printImageThumb(getAnnotatedImageTitle()); ?></div>
$str .= '<?php printImageThumb(getAnnotatedImageTitle()); ?>;'
<?php endwhile; ?>
<textarea type="text" size="50">
<?php echo $str; ?>
</textarea>
The code I've added is the $str stuff. I'm trying to loop through the images and create the html that is used in the first div in the while loop so that it puts it as text into the str string. This is concatenated for each image in the library and then the end str is posted into a simple text area for the user to copy.
I can't get the $str concatination working.
I'm very new to php and I can't quite get the syntax working.
Any help would be much appreciated.
The concatenation is not inside the <?php tags. For readability, you should use sprintf:
<?php $str = ''; ?>
<?php while (next_image()): ?>
<div class="imagethumb"><?php printImageThumb(getAnnotatedImageTitle()); ?></div>
<?php $str .= sprintf('%s',
html_encode(getImageLinkURL()),
getBareImageTitle(),
printImageThumb(getAnnotatedImageTitle()));
?>
<?php endwhile; ?>
But you are repeating things here (you are creating the link twice). You could restructure the code a bit to avoid that:
<?php
$images = array();
while (next_image()) {
$images[] = sprintf('%s',
html_encode(getImageLinkURL()),
getBareImageTitle(),
printImageThumb(getAnnotatedImageTitle()));
}
?>
<?php foreach($images as $image): ?>
<div class="imagethumb"><?php echo $image; ?></div>
<?php endforeach; ?>
<textarea>
<?php echo implode("", $images); ?>
</textarea>
Reference: implode
Your php code is starting and ending outside your php blocks with random php blocks in between.
<?php $str .= '<a href="';
$str .= html_encode(getImageLinkURL());
$str .= '" title="';
$str .= getBareImageTitle();
$str .= '">';
$str .= printImageThumb(getAnnotatedImageTitle());
$str .= '</a>';
?>
Alternatively:
<?php $str .= ''.printImageThumb(getAnnotatedImageTitle()).''; ?>
One issue is that ' and " strings behave differently in PHP. When you have:
echo '<?php echo $otherString; ?>';
PHP will print:
<?php echo $otherString; ?>
instead of the contents of $otherString.
I would rewrite this line:
<?php $str .= '<?php printImageThumb(getAnnotatedImageTitle()); ?>' ?>
to look more like this:
<?php $str .= '<a href="' . html_encode(getImageLinkURL()) . '" title="' . getBareImageTitle() . '" ' . printImageThumb(getAnnotatedImageTitle() . '</a>;'; ?>
Another issue is that you can't echo into a string and have it concatenate. Instead, you want to return a string value.
The $str variable is not enclose in <?php ?> tags.