I am trying to make a site using cakephp and twitter bootsrap. For the gallery I am making I am trying to display, using foreach, multiple images , but they simply don't show up. Everything is working, the foreach and the variable data, but the echos don't display anything. Could anyone help please?
Thanks in advance.
(code bellow from my show_images.ctp view)
<table >
<tr>
<?php
$i=0;
foreach( $gallery_images as $gallery_image ):?>
<td align=center>
<?php echo "<a id=\"single_1\" href=\"test/".$gallery_image['GalleryImage']['path']." ";?>
<?php echo "<img src=\"test/".$gallery_image['GalleryImage']['path'].", alt=\"".$gallery_image['GalleryImage']['path']."";?>
<?php echo "</a>";?>
</td>
<?php $i++;?>
<?php
if($i==4){
echo "</tr><tr>";
$i=0;
}
?>
<?php endforeach ?>
</tr>
you haven't close your tag inside echotry to change this:
<?php echo "<a id=\"single_1\" href=\"test/".$gallery_image['GalleryImage']['path']." ";?>
<?php echo "<img src=\"test/".$gallery_image['GalleryImage']['path'].", alt=\"".$gallery_image['GalleryImage']['path']."";?>
<?php echo "</a>";?>
to this:
<?php echo '<a id="single_1" href="test'.$gallery_image['GalleryImage']['path'].' >';?>
<?php echo '<img src="test'.$gallery_image['GalleryImage']['path'].'" alt="'.$gallery_image['GalleryImage']['path'].'" />';?>
<?php echo '</a>';?>
Related
This is an example of what I want to achieve
but what I was able to display is 1 product per row.
This is what I have done and but is not working as intended.
<ol>
<?php
$no = 1;
foreach($projects as $project):?>
<?php if($project['finish'] == 'no'):?>
<li><?=$no?></li>
<li><?=$project['type']?></li>
<li><?=$project['date_started']?></li>
<li><?=$project['brief_description']?></li>
<li><?=$project['full_description']?></li>
<li>
<?php foreach($images as $image):?>
<?php if($image['project_id'] == $project['id']):?>
<img src="img/<?=$image['name']?>">
<?php endif;?>
<?php endforeach;?>
</li>
<li>
Contact admin
</li>
<?php endif;?>
if($no % 5 === 0):
echo "<br>";
endif;
<?php $no++; ?>
<?php endforeach;?>
How can I get the code to display 5 lists per row
<html>
<body>
<table>
<?php
echo '<tr>';
for($i=1;$i<100;$i++)
{
echo '<td>'.$i.'</td>';
if($i%5==0)
{
echo $i;
echo '</tr><tr>';
}
}
?>
</table>
</body>
</html>
This will you the idea
I have had GROUP_CONCAT in MySQL database, so I have created view where is a row of an array of images. here it is:
I am using PHP CodeIgniter and I try to display this images on my page, but there is some problem: it shows only those images, which are not in an array in the table row.
here is my code to display:
<?php foreach ($get_hotels as $geth) { ?>
<td><img src="<?php echo base_url()."uploads/hotels/".trim(str_replace(",", " ", $geth->hotel_images));?>" width="73" height="53"></td>
<?php } ?>
So, my question is how to display pictures in same <td> as an array? any suggestions?
You can try with explode, like this :
$images = explode(',',$your query);
<?php foreach ($images as $key => $geth) { ?>
<td><img src="<?php echo base_url()."uploads/hotels/".$geth;?>" width="73" height="53"></td>
<?php } ?>
Hope this can help you
You can try the following method:
<?php
foreach($get_hotels as $geth):
$images = explode(',', $geth->hotel_images);
foreach($images as $image): ?>
<td>
<img src="<?= base_url() . "uploads/hotels/$image"; ?>" width="73" height="53">
</td>
<?php
endforeach; ?>
<?php
endforeach; ?>
This uses explode to separate the values by comma and then, runs a loop over them and prints the image tags.
I've created a rating star system that allows user to rate 1-5.
How do I change the numbers 1-5 to stars?
These are the codes below that show the numbers for the user to rate.
<?php foreach(range(1,5)as $rating):?>
<a href="rate.php?article= <?php echo $article->id; ?> &rating= <?php echo $rating ; ?> ">
<?php echo $rating; ?> </a>
<?php endforeach;?>
Are there any ways I can convert them to an image or do I have to redo my code?
Yeah for sure.
<?php foreach(range(1,5)as $rating):?>
<a href="rate.php?article= <?php echo $article->id; ?> &rating= <?php echo $rating ; ?> ">
<?php echo '<img src="images/rating_'.$rating.'.png">'; ?> </a>
<?php endforeach;?>
Now simply create the folder images and insert rating_1.png, rating_2.png and so on.
BTW: Maybe it is easier and better for you when you use it in this way (only to show):
<?php
$bla = $article->id;
foreach(range(1,5)as $rating){
echo('
<a href="rate.php?article='.$bla.'&rating='.$rating.'">
<img src="images/rating_'.$rating.'.png">
</a>
');
}
?>
I am trying to display data from two different Mysql tables in the same html table. Do do that I have put a while loop inside another while loop. The problem is that in the table the data of the second loop is displayed only on the first raw of the html table. I really don't know what is wrong. Thanks for your help.
<?php
while($results = mysql_fetch_array($raw_results)){
echo '<td>';
echo '<a href="linkto.php?data='.ucfirst($results['song_name']).'" class="iframe"><img src="icons/1384070574_95.png"> ';
echo '<a href="'.ucfirst($results['song_name']).'" class="clapping">';
echo '<img src="icons/Hand-icon.png" id="songs'.$pictureid.'" onClick="action(\'songs'.$pictureid.'\')"/></a>';
echo '</td>';
echo '</tr>';
if (isset($userid)){
echo '<td>
<div id="cssmenu">
<ul>
li class="has-sub><span><img src="icons/1384074758_document_music_add.png"></span>
<ul>
<li class="has-sub"><span>Create a Playlist</span></li>';
while($playlist = mysql_fetch_array($raw_playlist)){
echo'<li class="has-sub"><span>'.ucfirst($playlist['title']).'</span></li>';
}
echo'</ul>
</li>
</ul>
</div>
</td>';
}
echo' </tr>
';
$pictureid = $pictureid + 1;
$songid= $songid + 1;
}
echo '</tbody>';
?>
As mentioned in the comments, you may have a problem with your nested data depending on what you're trying to show.
However, your HTML is a mess, missing some opening and closing tags, which may mean that some data is being sent to the browser but not being displayed. Have you looked at the source of the page in the browser to check the data is not there? Until you do, we cannot be sure whether the missing data is an HTML, SQL or PHP error.
You should try to limit the amount of HTML that you echo from PHP for this reason, and I've tidied it up a bit and added missing tags below. See if that helps at all.
<?php while ($results = mysql_fetch_array($raw_results)) : ?>
<tr>
<td>
<img src="icons/1384070574_95.png">
<img src="icons/Hand-icon.png" id="songs<?php echo $pictureid; ?>" onClick="action('songs<?php echo $pictureid; ?>')" />
</td>
</tr>
<?php if (isset($userid)) : ?>
<tr>
<td>
<div id="cssmenu">
<ul>
<li class="has-sub><span><img src="icons/1384074758_document_music_add.png"></span>
<ul>
<li class="has-sub"><span>Create a Playlist</span></li>
<?php while ($playlist = mysql_fetch_array($raw_playlist)) : ?>
<li class="has-sub"><span><?php echo ucfirst($playlist['title']); ?></span></li>
<?php endwhile; ?>
</ul>
</li>
</ul>
</div>
</td>
<?php endif; ?>
</tr>
<?php
$pictureid++;
$songid++;
endwhile;
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.