I am trying to load pictures from database to jquery slider
infact what is stored at database is the name of the picture
i implemented this code, it's working without errors but it showing me nothing at slider all is empty
<div id="slider">
<?php
while ($result = mysqli_fetch_object($banner)):
?>
<img src="images/banner/<? $banner['picture'];?>/" width="950" height="400"alt="" title="<strong><? echo $banner['title'];?></strong><span><? echo $banner['description'];?> </span>" />
<?php
endwhile
?>
</div>
name of the table at database is banner in which i have id(INT), picture(varchar 50) title(varchar(100), description(longblob)
query is working and returning number of selected rows
but nothing is shown
You need to echo the result rather than just use the variable...
<div id="slider">
<?php
while ($result = mysqli_fetch_object($banner)):
?>
<img src="images/banner/<?php echo $banner['picture'];?>" width="950" height="400" alt="" title="<strong><? echo $banner['title'];?></strong><span><?php echo $banner['description'];?></span>" />
<?php
endwhile;
?>
</div>
Related
<?php foreach($works as $work) : ?>
<?php echo Asset::img('project-icons/icon/$work->cover_img', array('class'=>'img-responsive', 'alt'=>'...')); ?>
<?php endforeach; ?>
I am using FuelPHP to build a portfolio website. PHP v5.6
This is the "works" section where images and details of a "work" are fetched from database. Using foreach loop. I want to get the "cover_img" (which is the image name), inside the Asset::img(..)
How to do this? what to put in place of $work->cover_img?
Edit: I was able to get the result by using this:
<img src="<?php echo Uri::base(false); ?>/assets/img/project-icons/icon/<?php echo $work->cover_url; ?>" class="img-responsive" alt="..." />
Can this be achieved by using Asset::img() instead of Uri::base()?
Can't you just do:
<?php
echo Asset::img('project-icons/icon/'.$work->cover_img, array('class'=>'img-responsive', 'alt'=>'...'));
?>
...?
I need some help, I have a repeat region which displays pics from a database, when I click on the image I would like to go to another page where there is a photo gallery to display my pictures bigger.
My problem, no matter which thumb I click I get the same set of pictures from the database, which is usually the last thumb listed.
I am new to php, so i am wondering if anyone can help me, thank you.
Code for thumb page
`
<?php do { ?>
<div class="display-property-pic">
<input type="image" id="imageIn1" src="upload/images/<?php echo $row_repeatRegion['thumb']; ?>" alt="Submit" width="100" height="100" ><input name="picHid" type="hidden" value="<?php echo $row_repeatRegion['property_pic1']; ?>">
</div>
<?php } while ($row_repeatRegion = mysqli_fetch_assoc($repeatRegion)); ?>
`
Code for Gallery page
if(isset($_POST['picHid'])){
$pic = $_POST['picHid'];
}
mysqli_select_db($wiplisttest, $database_wiplisttest);
$query_getPics = "SELECT photos.photo_id, photos.pic1, photos.pic2, photos.pic3 FROM photos WHERE photos.property_pic1 LIKE '%$pic%'";
$getPics = mysqli_query($wiplisttest, $query_getPics) or die(mysql_error($wiplisttest));
$row_getPics = mysqli_fetch_assoc($getPics);
$totalRows_getPics = mysqli_num_rows($getPics);
<div class="album">
<div class="description">fixed images</div>
<ol>
<?php do { ?>
<li>
<h4><?php echo "Pic"." ".$row_getPics['pic3']; ?></h4>
<div class="description">Salzburg, Austria</div>
<a href="upload/images/<?php echo $row_getPics['pic3']; ?>">
<img src="upload/images/<?php echo $row_getPics['pic2']; ?>" />
</a>
</li>
<?php } while ($row_getPics = mysqli_fetch_assoc($getPics)); ?>
</ol>
</div>
As you have stored images info in database, there should be id assigned to each image, so when you click on any specific image, get id of that image and retrieve that image on another page using the id.
I have a loop in my view that outputs all the content gathered from the database:
<?php foreach($content as $contentRow): ?>
<?php
echo $contentRow->value;
?>
<?php endforeach; ?>
This works fine for HTML strings like:
<h2><strong>Example Text</strong></h2>
however I have some image content that I would like to display and I have tried the following database entries to no avail:
<img src="<?php echo site_url('pathToImage/Image.png'); ?>" alt="Cover">"
<img src="site_url('pathToImage/Image.png')" alt="Cover\">"
I feel like I am missing a step on how to use PHP values in this way.
How do I access the URL of the image and use that to show the image?
Full Code Edit
<?php
$CI =& get_instance();
?>
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="col-md-2"></div>
<div class="col-md-20">
<!--<form class="form-center" method="post" action="<?php echo site_url(''); ?>" role="form">-->
<!-- <h2 class="">Title</h2>
<h2 class=""SubTitle/h2>-->
<?php echo $this->session->userdata('someValue'); ?>
<!--//<table class="" id="">-->
<?php foreach($content as $contentRow): ?>
<tr>
<td><?php
echo $contentRow->value;
?></td>
</tr>
<?php endforeach; ?>
<!--</table>-->
<!--</form>-->
</div>
<div class="col-md-2"></div>
</div>
</div>
</div><!-- /.container -->
and the values are being read out in $contentRow->value;
I have to verify this, but to me it looks like you are echo'ing a string with a PHP function. The function site_url() is not executed, but simply displayed. You can execute it by running the eval() function. But I have to add this function can be very dangerous and its use is not recommended.
Update:
To sum up some comments: The use of eval() is discouraged! You should reconsider / rethink your design. Maybe the use of tags which are replaced by HTML are a solution (Thanks to Manfred Radlwimmer). Always keep in mind to never trust the data you display, always filter and check!
I'm not going to accept this answer as #Philipp Palmtag's answer helped me out alot more and this is more supplementary information.
Because I'm reading data from the database it seems a sensible place to leave some information about what content is stored. In the same table that the content is stored I have added a "content type" field.
In my view I can then read this content type and render appropriately for the content that is stored. If it is just text I can leave it as HTML markup, images all I need to do is specify the file path and then I can scale this as I see fit.
I have updated my view to something akin to this and the if/else statement can be added to in the future if required:
<?php foreach($content as $contentRow): ?>
<?php if ($contentRow->type != "image"): ?>
<?php echo $contentRow->value; ?>
<?php else: ?>
<?php echo "<img src=\"".site_url($contentRow->value)."\">"; ?>
<?php endif; ?>
<?php endforeach; ?>
So I have a mediaelement.js audio player and I'm using the advanced custom fields plugin and I want to be able to display the title of the current track on the player, here's my code
<audio class="mejs-new" style="width: 100%; height: auto;" controls width="100%" height="auto">
<?php if(get_field('audio_repeater')): ?>
<?php while(has_sub_field('audio_repeater')): ?>
<?php $title = get_sub_field('music_title'); ?>
<source src="<?php the_sub_field('music_url'); ?>" title="<?php echo $title; ?>" type="audio/mp3">
<p><?php echo $title; ?></p>
<?php endwhile; ?>
<?php endif; ?>
</audio>
Edit..
I have tried echoing the title outside the audio tag but it only echoes the 2nd track title and won't change when changing tracks.
If I understand correctly, you're wanting to move the title outside the <audio /> tag, but you can only get the title from within the loop.
You're almost there actually - the easiest way to do this is to set the title to a variable while you're in the loop, which you're already doing ($title = get_sub_field('music_title');). So now, all you need to do is echo the variable when you need it.
Because you've already set the variable while you had access to the functions in the loop, you can now echo that variable afterwards without needing the loop.
For example:
<?php endif; ?>
</audio>
<p><?php echo $title; ?></p>
EDIT:
I assumed you only had one title and I didn't question why you were using a repeater with one title :) To print out a list of the titles afterwards, you can use a similar approach, except this time you need to save the results of the loop and then loop through it again.
The easiest way to do this is to repeat the entire loop code but only print out the title, but that's a little inefficient. Ideally, we should only be getting the field once. Here's another way to do the whole thing:
<?php $audio_repeater = get_field("audio_repeater"); ?>
<audio class="mejs-new" style="width: 100%; height: auto;" controls width="100%" height="auto">
<?php if((array) count($audio_repeater)): ?>
<?php foreach($audio_repeater as $audio_source): ?>
<source src="<?php echo $audio_source["music_url"]; ?>" title="<?php echo $audio_source["music_title"]; ?>" type="audio/mp3">
<?php endforeach; ?>
<?php endif; ?>
</audio>
<?php foreach($audio_repeater as $audio_source): ?>
<p><?php echo $audio_source["music_title"]; ?></p>
<?php endforeach; ?>
In this example, we're grabbing the entire ACF repeater once at the top, and assigning it to a variable. We're then checking it has items in it, and looping through those items.
This is an alternative way to use ACF repeaters, which might not quite be as easy as using the loop functions, but it is more extensible when you're moving things around a bit.
Im little bit stuck on a logic.scenario is i have a slider where two images are shown at a time taking 50%-50% part of screen,here is the simple html of it,
<div class="zeus-slider zeus-default" >
<div class="zeus-block">
<div class="zeus-slide s-50"> <img src="slider/slider1.jpg" data-effect="slideRight" alt="" /> </div>
<div class="zeus-slide s-50"> <img src="slider/slider2.jpg" data-effect="slideRight" alt="" /> </div>
</div>
</div>
here every block contains two images i have shown only one.now i have trying to make it dynamic, but i didnt get any idea how it will work, so i created database with two tables, each for individual image in a single block.Both table have fields like simg_id(A_I),img_name,simg_path.
here its my php on slider page.
<div class="zeus-block">
<?php
$slider_slt=getResultSet('select * from slider_img_master1 ORDER BY simg_id');
if(mysql_num_rows($slider_slt))
{
while($slider_data=mysql_fetch_assoc($slider_slt))
{
?>
<div class="zeus-slide s-50"> <img src="slider/first/<?php echo $slider_data['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
<?php
$slider_slt2=getResultSet('select * from slider_img_master2 ORDER BY simg_id');
if(mysql_num_rows($slider_slt2))
{
while($slider_data2=mysql_fetch_assoc($slider_slt2))
{
?>
<div class="zeus-slide s-50"> <img src="slider/second/<?php echo $slider_data2['simg_path']?>" data-effect="slideRight" alt="" /> </div>
<?php }
} ?>
</div>
now the problem is when i try to fetch path of image in slider, images are not changing one by one on both half of screen.instead it showing like both images from from both table top, another two images from both tables below 1st both, and so on , so full page is covered with images.
I know this idea of creating two tables for getting two images at once is silly,but i could not think any better.if any one can suggest any better way, it would be so helpful.
Update:getResultSet is function for mysql_query.
if anybody interested i found an answer for above question.
<div id="slide1" >
<div class="zeus-slider zeus-default" >
<?php
$slider_str="select *from slider_img_master1 where simg_status='Active'";
$i=1;
$result=mysql_query($slider_str);
if(mysql_num_rows($result)>0)
{
echo '<div class="zeus-block">';
while($row=mysql_fetch_assoc($result))
{
if($i%2==1 && $i!=1)
{
echo '<div class="zeus-block">';
}
?>
<div class="zeus-slide s-50"> <img src="slider/<?php echo $row['simg_path'];?>" data-effect="slideRight" alt="" /> </div>
<?php
if($i%2==0)
{
echo '</div>';
}
$i++;
}
} ?>
</div>
<div class="clear"> </div>
<div class="next-block"> </div>
<div class="prev-block"> </div>
</div>