I want to load images from my database that if someone clicks on it brings them to another page but instead it just shows $r[n]
Here is the code:
<?php
$cn=mysql_connect('localhost', 'root', '');
mysql_select_db('db', $cn);
$query="SELECT * FROM tblg";
$res=mysql_query($query,$cn);
$r = mysql_fetch_array($res);
?>
<?php
if ((isset($_GET['guide'])))
{
$guide=$_GET['guide'];
}
else
{
$guide="";
}
?>
<IMG SRC='$r[a]' WIDTH="120" HEIGHT="120" ALT="$r[n]">
<?php
if ($guide == "t")
{
include('t.php');
}
elseif ($guide == "a")
{
include("a.php");
}
?>
Change
<IMG SRC='$r[a]' WIDTH="120" HEIGHT="120" ALT="$r[n]">
to
<IMG SRC='<?php echo $r[a]; ?>' WIDTH="120" HEIGHT="120" ALT="<?php echo $r[n]; ?>">
change
<IMG SRC='$r[a]' WIDTH="120" HEIGHT="120" ALT="$r[n]">
into
<img src='<?php echo $r[a]; ?>' width="120" height="120" alt="<?php echo $r[n]; ?>">
Note that using caps in your code is not really a good way of coding
Related
I'm new to PHP and I know this is an easy one but still can't find a solution.
I have an array that holds 4 different images and I want to echo the results
so my HTML looks like this:
<img src="<?php echo $results['image1']?>" >
<img src="<?php echo $results['image2']?>" >
<img src="<?php echo $results['image3']?>" >
<img src="<?php echo $results['image4']?>" >
But what if for example image4 is null? - i don't want to echo the whole
<img src> tag line
How can i do it?
Thanks?
Here is your work around example.
<?php
if(!empty($results['image1'])) echo '<img src="'.$results['image1'].'">';
if(!empty($results['image2'])) echo '<img src="'.$results['image2'].'">';
if(!empty($results['image3'])) echo '<img src="'.$results['image3'].'">';
if(!empty($results['image4'])) echo '<img src="'.$results['image4'].'">';
?>
try this code may it helps you. here i have check first if result not empty.
<?php if(isset($results['image1']) && !empty($results['image1'])){ ?><img src="<?php echo htmlspecialchars($results['image1']}; ?>" ><?php } ?>
<?php if(isset($results['image2']) && !empty($results['image2'])){ ?><img src="<?php echo htmlspecialchars($results['image2']}; ?>" ><?php } ?>
<?php if(isset($results['image3']) && !empty($results['image3'])){ ?><img src="<?php echo htmlspecialchars($results['image3']}; ?>" ><?php } ?>
<?php if(isset($results['image4']) && !empty($results['image4'])){ ?><img src="<?php echo htmlspecialchars($results['image4']}; ?>" ><?php } ?>
<?if(isset($results['image1']) && $results['image1'] != ""){?><img src="<?=$results['image1']?>" ><?}?>
With this you check it the image is set. Do that for each of your images and you should be fine.
The isset is not necessary, but some setups of php throw a warning without it. Thus it's better practice to use it.
If you don't want all the short-tags, do it like this:
if(isset($results['image1']) && $results['image1'] != ""){echo "<img src='{$results['image1']}' >"; }
That should be about the fanciest you can do. the "x{$variable}y" works like "x".$variable."y" but is easier to write/read, if you like it.
How to retrieve the images if there are multiple images in a single row. I am using this below code to get the images. if there is single image it is displaying. But, I need to display multiple images.
Here is my code:
<?php if(!empty($img['image'])) { ?>
<img src="<?php echo $img['image'];?>" width="100px" height="50px"/>
<?php }else {?>
<img src="image/data/photo/profile1.png" width="100px" height="50px"/>
<?php }?>
I used this function in view for displaying the images
<?php
if(!empty($img['image'])) {
$images = explode($img['image'],',');
foreach($images as $image)
{
print '<img src="' . $image . '" width="100px" height="50px"/>';
}
}else {
print '<img src="image/data/boutique/profile1.png" width="100px" height="50px"/>';
}
?>
or
<?php
if(!empty($img['image'])) {
$images = explode($img['image'],',');
foreach($images as $image)
{
?>
<img src="<?php print $image ?>" width="100px" height="50px"/>
<?php
}
}else {
?>
<img src="image/data/boutique/profile1.png" width="100px" height="50px"/>
<?php
}
?>
I am trying to figure out how to change the photo without the page refreshing. I have seen some of the example but just cannot figure out how to implement it in to my working page.
This is what I have right now:
<div id="propertyDetailsImage">
<img class="image photo" src="<?php echo $property->photos->photo[$mainPhoto - 1]->url; ?>" width="<?php echo $property->mainPhotoWidth * 0.77 ?>" height="<?php echo $property->mainPhotoHeight * 0.77 ?>" alt="<?php echo $property->address->full; ?>"/>
</div>
<div class="photoPosition">
<?php
$previousPhoto = $mainPhoto - 1;
if($previousPhoto == 0) {
$previousPhoto = $property->totalPhotos;
}
$nextPhoto = $mainPhoto + 1;
if ($nextPhoto > $property->totalPhotos) {
$nextPhoto = intval(1);
}
?>
<img src="images/previous.png" alt="Previous photo" height="12" width="13" border="none"/>
<span id="photoPosition"><?php echo $mainPhoto; ?></span> of <?php echo $property>totalPhotos; ?>
<img src="images/next.png" alt="Next photo" height="12" width="13" border="none" />
</div>
</div>
<div class="col-md-6">
<div id="thumbnails">
<h3 class="additional">Photos</h3>
<?php
// Iterate throught the list of photos
foreach($property->photos->photo as $photo) {
?>
<script type="text/javascript">
addPhoto(
<?php echo $photo->id; ?>,
<?php echo $photo->width; ?>,
<?php echo $photo->height; ?>,
"<?php echo $photo->caption; ?>");
</script>
<img src="<?php echo $photo->url; ?>" width="<?php echo $photo->widthSmall; ?>" height="<?php echo $photo->heightSmall; ?>" class="image photo" id="photo<?php echo $photo->position; ?>" alt="Additional Photo of <?php echo $photo->address->advertising; ?>" onclick="return showPhoto(<?php echo $photo->position; ?>)" />
<?php }
?>
Any help is appreciated. Cheers
Dima
You should use ajax to get like this results.
you should go here,
The image slider shown in this demo is for free.
For detailed instructions, please visit online
http://www.menucool.com/slider/javascript-image-slider-demo1
I've written the following PHP statement but everytime i try to combine it into an else/if, it breaks.
Can someone please advise? I'm new to PHP and am getting a tad stuck.
Thanks :)
<?php if (is_page( 19 ) ) {?>
<div class="imageSlider"><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image2.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image3.jpg" alt="" /></div>
<?php }?>
<?php if (is_page( 23 ) ) {?>
<div class="imageSlider"><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /></div>
}
<?php }?>
Use this syntax :
<?php if (condtion):?>
// html goes here,
<?php elseif(condtion): ?>
// html goes here,
<?php endif; ?>
<?php if (is_page( 19 ) ) {?>
<div class="imageSlider"><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image2.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image3.jpg" alt="" /></div>
<?php } elseif (is_page( 23 ) ) {?>
<div class="imageSlider"><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /><img src="<?php echo bloginfo('template_directory');?>/Images/mainImages/innerPage-Image.jpg" alt="" /></div>
<?php }?>
Here is an sample if/else using your code
<?php if (is_page(19)) { ?>
//Insert html
<? { elseif (is_page(23)) } ?>
//Insert other html
<? } ?>
Consider the following :
$img_pathm = JURI::root().'images/properties/images/'.$this->datos->id.'/';
$peque_path = JURI::root().'images/properties/images/thumbs/'.$this->datos->id.'/';
$result = count($this->Images);
$resultf = $result-1;
while ($resultf>=0){ ?>
<span class="editlinktip hasTip" title="<?php echo $this->datos->image1;?>::
<img border="1" src="<?php echo $peque_path.$this->Images[$resultf]->name; ?>" name="imagelib" alt="<?php echo JText::_( 'No preview available'.$img_pathm ); ?>" width="206" height="100" />">
<img src="<?php echo $peque_path.$this->Images[$resultf]->name; ?>" alt="Additional image <?php echo $resultf+1 ?>" width="65px" height="50px"/></span> <?php
$resultf--; }
This currently prints images one after the other. All I need to do is to invert the order in which these images are printed to the user. I am not sure where, or how I would insert something similar to ORDER by in this code? Thanks in advance!
Just loop the other way:
$img_pathm = JURI::root().'images/properties/images/'.$this->datos->id.'/';
$peque_path = JURI::root().'images/properties/images/thumbs/'.$this->datos->id.'/';
$result = count($this->Images);
$resultf = 0;
while ($resultf<$result){ ?>
<span class="editlinktip hasTip" title="<?php echo $this->datos->image1;?>::
<img border="1" src="<?php echo $peque_path.$this->Images[$resultf]->name; ?>" name="imagelib" alt="<?php echo JText::_( 'No preview available'.$img_pathm ); ?>" width="206" height="100" />">
<img src="<?php echo $peque_path.$this->Images[$resultf]->name; ?>" alt="Additional image <?php echo $resultf+1 ?>" width="65px" height="50px"/></span> <?php
$resultf++; }
Maybe you can use array_reverse