I am trying to implement the jQuery live thumbnails with my PHP page. On the page I am retrieving event information along with a comma separated list of thumbnail values. The plugin works a bit differently that that and I am having difficulty adapting my script to work. The plugin is located here http://tutorialzine.com/2012/12/album-photo-previews-jquery/. In their example they use an array while I have a comma separated list of thumbnails. The code I have so far is here...
<?php foreach ($events as $event) { ?>
<div class="left13 section_home" style="margin-bottom:25px;">
<h2><?php echo $event['event_title']; ?></h2>
<div align="center">
<?php foreach ($event['thumbnails'] as $thumbnail) { ?>
<a href="#" data-images="<?php echo str_replace(',', '|', $event['thumbnails']); ?>" class="album">
<img src="<?php echo ($event['thumbnails'] != '') ? base_url() . 'media/photos/thumbnail/' . $event['thumbnails'] : base_url() . 'images/no_photo_thumbnail.png'; ?>" alt="" title="" /><span class="preloader"></span></a>
<p><?php echo ($event['event_description'] != '') ? substr($event['event_description'], 0, 200) : 'No description yet...'; ?></p>
<span class="swirl_left"><span class="swirl_right">View This Event</span></span>
<?php } ?>
</div>
</div>
<?php } ?>
How would I be able to make this script work by using a comma separated list of thumbnail values instead of the array used in the tutorial? Thanks!
I figured it out and the answer is quite simple. First, my data coming from the database included a comma separated list of thumbnails. I just used the proper functions to insert that data into the script. The only problem I have now is that I need to add the path to the beginning of each value in the comma separated list. Is there a PHP function to do that? Below is my almost finished code.
<div class="content">
<?php foreach ($events as $event) {
// Create an array out of the comma separated list of thumbnails
$thumbnails = explode(',', $event['thumbnails']); ?>
<div class="left13 section_home" style="margin-bottom:25px;">
<h2><?php echo $event['event_title']; ?></h2>
<div align="center">
<img src="<?php echo base_url() . 'media/photos/thumbnail/' . $thumbnails[0]; ?>" alt="" title="" /><span class="preloader"></span>
<p><?php echo ($event['event_description'] != '') ? substr($event['event_description'], 0, 200) : 'No description yet...'; ?></p>
<span class="swirl_left"><span class="swirl_right">View This Event</span></span>
</div>
</div>
<?php } ?>
</div>
To finish this up I need to add the following to the beginning of each item in $event['thumbnails']...
<?php echo base_url(); ?>media/photos/thumbnail/
Then it should work perfectly.
Related
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 implement a simple pagination using PHP and Twitter Bootstrap but got stuck.
Everything seems to work fine the only problem is my div's are floating all around leaving some empty spaces in the page like in this picture:
Below is my code:
<?php foreach($tester as $data): ?>
<div class="col-sm-2">
<img src="" width="150" height="150"/>
<br>
<span><?php echo $data['Description'];?></span><br>
<span><?php echo $data['Unit_Price'];?></span><br>
<span>In Stock:<?php echo $data['Qty'];?></span><br>
<span>Arriving Soon:<?php echo $data['In_Transit'];?></span><br>
<span>Show All Products In:<?php echo $data['P_Class_Name'];?></span>
</div>
<?php endforeach;?>
Put class="clearfix" div after each 6 elements to create non float sensitive line break
<?php $i=0; foreach($tester as $data): $i++; ?>
<div class="col-sm-2">
<img src="" width="150" height="150"/>
<br>
<span><?php echo $data['Description'];?></span><br>
<span><?php echo $data['Unit_Price'];?></span><br>
<span>In Stock:<?php echo $data['Qty'];?></span><br>
<span>Arriving Soon:<?php echo $data['In_Transit'];?></span><br>
<span>Show All Products In:<?php echo $data['P_Class_Name'];?></span>
</div>
<?php if ($i % 6 == 0) { ?><div class="clearfix"><?php } ?>
<?php endforeach;?>
However, this solution shouldn't be used if you need a different number of elements to displayed per row for a different viewpoint size.
I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg;, I tried to seperate each path by using explode, getting all the images as array but not able to pick single path-
<div class="col-sm-6 masonry-item">
<a href="<?php echo Url::to(['site/roompage']); ?>" class="product_item text-center">
<span class="product_photo bordered_wht_border">
<?php
foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img)
{
?>
<?php echo Html::img('#backend/web'.'/'.$value_img);?>
<?php
}
?>
</span>
<span class="product_title"><?php echo $row['room_type']; ?></span>
<span class="product_price">Rs.<?php echo $row['rate']; ?></span>
</a>
</div>
<?php endforeach; ?>
<?php
// if you want only the first image is better
$my_image = explode(';',rtrim($row['images'],';'),1);
echo Html::img('#backend/web'.'/'.$my_image[0]);
}
?>
otherwise
<?php
// if you want all the image
foreach (explode(';',rtrim($row['images'],';')) as $key_img => $value_img)
{
echo Html::img('#backend/web'.'/'.$value_img);
}
?>
this because (explode(';',rtrim($row['images'],';'),1) return an array of two element (the first and the rest)
The src parameter, containing the backend alias, will be processed by Url::to()
Check the docs for details on Html::img()
I have written a PHP on a page displaying info from an XML feed to another website. On the feed I have a product image that we would like to display, but I need to add the external website address as a prefix in order for this to work.
Code I have on the feed is:
$xml = simplexml_load_file('feed/myfeed.xml');
foreach ($xml->item as $item) {
$short_description = substr($item->descshort, 0, 200); ?>
<div class="row">
<div class="lhs col-md-9">
<h3><?php echo $item->name ?></h3>
<p class="pri">£<?php echo $item->regprice ?></p>
<p id="shown">
<?php echo $short_description; ?> ... Read more</p>
</div>
<div class="rhs col-md-3"> //The following is the bit that I am struggling on
<img src="<?php echo 'http://mywebsite.com/myimagefolder/mysubimagefolder/' . $item->imgsm; ?>" alt="<?php echo $item->name ?>" height="150" />
</div>
</div>
But all this gives me is a warning message that I have just tried to access http://mywebsite.com/myimagefolder/mysubimagefolder/
So basically how could I add http://mywebsite.com/myimagefolder/mysubimagefolder/ on the beginning and the filename after it?
Its probably very simple, but not to me. Please could anyone help me?
Many thanks in advance.
I have just tried:
<img src="http://mywebsite.com/myfolder/mysubfolder/<?php echo $url, $item->imgsml ?>" alt="<?php echo $item->name ?>" height="150" />
And this seems to work throughout. And this seems to work throughout. Thanks #schenk, your answer was spot on.
Been looking around and am stumped. Basically I'm trying to filter out a result from an xml feed and hide it from displaying in the html output. I'm trying to find out the venue "Hornblower Cruises and Events" and if it exists, hide the whole , which is the parent of all the nodes.
Here's the URL: http://www.sandiegomagazine.com/goldstartest/rss3-exclude.php
Here's my code:
<?php
$myfeed = simplexml_load_file('https://www.goldstar.com/api/listings.xml?api_key=6d0d598c69dfecfcf028b0d2b3c9b693b606ad8c&postal_code=92101');
$i = 0;
foreach ($myfeed as $goldstar):
$title=$goldstar->headline_as_html;
$summary=$goldstar->summary_as_html;
$dates=$goldstar->upcoming_dates->event_date->date;
$ourprice=$goldstar->our_price_range;
$fullprice=$goldstar->full_price_range;
$img=$goldstar->image;
$link=$goldstar->link;
$venue_name=$goldstar->venue->name;
$venue_street=$goldstar->venue->address->street_address;
$venue_locality=$goldstar->venue->address->locality;
$venue_region=$goldstar->venue->address->region;
$venue_zip=$goldstar->venue->address->postal_code;
$venue_phone=$goldstar->venue->phone;
$category=$goldstar->category_list->category->name;
// if ($venue_name == 'Hornblower Cruises and Events'){
// unset($myfeed->event);
//echo $myfeed->asxml();
//}
if (++$i > 20) {
// stop after 10 loops
break;
}
?>
<html>
<head></head>
<body>
<div class="gs-item">
<div class="gs-itemcontent">
<h3 class="gs-cat"><?php echo $category; ?></h3>
<h2><?php echo $title; ?></h2>
<h4 class="gs-date">Date: <?php echo $dates; ?> <br/>For more show dates, click here</h4>
<img src="<?php echo $img; ?>" />
<p><?php echo $summary; ?></p>
<div id="gs-callout">
<span class="fullprice">Full Price: <?php echo $fullprice; ?></span>
<br/>
<span class="ourprice">Our Price: <span class="gs-hilite"><?php echo $ourprice; ?></span></span>
<p><a class="gs-button" href="<?php echo $link; ?>" target="_blank">Buy Tickets »</a></p>
</div>
<ul class="gs-venue">
<li><strong><?php echo $venue_name; ?></strong> | </li>
<li><?php echo $venue_street; ?></li>
<li><?php echo $venue_locality; ?>, <?php echo $venue_region; ?> <?php echo $venue_zip; ?></li>
<li><?php echo $venue_phone; ?></li>
</ul>
</div>
<div class="gs-clear"></div>
</div>
<? endforeach; ?>
</body>
Help?
Use a keyed foreach
foreach ($myfeed as $key => $goldstar):
And then unset the entire current xml using the key
unset($myfeed->$key);
Or unset just the venue with unset($myfeed->$key->venue);
Alternately, you could just build a new obj instead of trying to edit the existing one. Instantiate a new object before your loop and then only add the pieces to it that you want to keep.
Or, you can just continue the foreach if you find the unwanted venue. The only downside is that you won't have a copy of your ok'd list in $myfeed. So...
if ($venue_name == 'Hornblower Cruises and Events') { continue; }
Firstly you should cast every object that you are getting from your SimpleXML object to the relevant type. For example you should cast string attributes or nodes with putting (string) before reading the field:
$venue_name = (string)$goldstar->venue->name
For your question about filtering, I'd suggest your own way to keep looking for the match string and then decide to add or not.
EDIT
You're trying to see if the venue name is 'Hornblower Cruises and Events' then unset the current event field and echo it as XML? Firstly you should write unset($myfeed) because it's the event field itself. Next asxml would return nothing if you unset $myfeed. And you have HTML mistake in your code. In every loop of your for, you're writing:
<html>
<head></head>
<body>
You should place them before the for. And there is no closing tag for them. Put the closing tags after for. If you want to just get the fields with not venue name 'Hornblower Cruises and Events', put the <?php if($venue_name != 'Hornblower Cruises and Events') : ?> before <div class="gs-item"> and put <?php endif; ?> after </ul>.