I am trying to find picid in array but it's not working. When I echo it, nothing appears.
Here is my code
<?php $psql=mysql_query("select * from gallery where userId='$miid'");
$photo1 = array();
while($photo=mysql_fetch_assoc($psql)) {
$photo1[]=$photo;
print_r($photo);
}
foreach($photo1 as $k => $v){
if($v['picId']==$mipic){
$pic="uploads/".$v['photo'];
echo ">>>". $key=array_search($v['picId'],$photo1);
?>
NEXT
<img src="<?php echo $pic; ?>" width="300px" height="300px">
PREVIOUS
<?php
}
}?>
array_search is not recursive. $v exists in $photo1, while $v['picId'] only exists in $v.
That makes $key=array_search($v['picId'],$photo1) return false which, when you echo it, will print as nothing.
I am not sure why you are using array_search at all. In order to retrieve the next and previous picId, try this:
NEXT
<img src="<?php echo $pic; ?>" width="300px" height="300px">
PREVIOUS
Beware though that one of the hrefs is modules/gallery/miloader.php while the other is just miloader.php. So unless you actually have two different miloader.php files (one in each of the directories), one of them is wrong.
Related
I have Tried Many Solution , Inside and Outside PHP Code , None of them are working
I am able to fetch Image Path from Array But Not able to assign it ..
I Tried following solutions :
foreach ($data as $item) {
echo "Image Path is ".$item[0]["Image"] ; //--> Returning - img01.jpg
$imageNumber= "img01";
//sol 1.
echo '<img src="'.$item[0]["Image"]'">';
//sol 2.
// echo "<img src=\"{$imageNumber}.jpg\">";
//sol 3.
//echo '<img src="'.$coverlink.'" alt="Cover">';
}
//sol 4.
// <img src="<?php echo $imageNumber ?>.jpg">
//sol 5.
// <img src="<?php echo $item[0]["Image"]; ?>">
I need some guidence what I am missing ?Any Help would be appreciated
From what you've posted, it seems like $item[0]["Image"] returns the image name along with the extension. E.g: img01.jpg.
So, you can simply put this within the img src.
foreach ($data as $item) {
echo "<img src='".$item[0]["Image"]."' />";
}
If your question is explained clearly, then this should work just fine.
I have a straightforward if statement to evaluate whether or not an image is set to appear as the logo on a WordPress build. If it returns empty/false, it displays a default image whose location is set as an absolute value.
The problem is when an image ISN'T set, the else statement is failing. I'm not receiving an error, but the code returned is simply an image tag without any source i.e. "< img src >".
Here is the statement:
<?php
$logo = $wp_options['header_logo'];
if(isset($logo) && ($logo !='')) { ?>
<img src="<?php echo $logo['url']; ?>">
<?php } else { ?>
<img src="wp-content/themes/wpdev/images/logo.png">
<?php } ;?>
I guess that if statement is failing, because you are treating $logo variable as a string.
It seems you're using $logo variable as an array, if you want to check out if it is empty you can use is_null() function of PHP.
By the way, we can't understand your problem this way, you should be more specific. Share your error or warning messages, the way it's behaving, etc..
Found a solution to this by specifically referring to the url of the image array when the variable $logo was defined. This way, the IF is evaluating the URL of the image.
The problem seemed to be that the initial IF was being evaluated as TRUE but obviously not returning the URL as this wasn't originally specified in $logo. By looking for the URL in the 'header_logo' array, it corrected the problem.
<?php
$logo = $wp_options['header_logo']['url'];
if(isset($logo) && ($logo !='')) { ?>
<img src="<?php echo $logo; ?>">
<?php } else { ?>
<img src="<!-- Image Location -->">
<?php } ;?>
I am sure this is a simple principle of PHP, however it is one I am yet to learn. In principle the code works:
<?php
for($i=0;$i<count($photos);$i++){
if($photos[$i]->image != ""){
if(JPATH_ROOT.'/images/'.$row->id.'/medium/'.$photos[$i]->image){
if(!$photocount) {
$photocount = $photocount + 1;
$photoclass = "property_photo_main property_photo_main_" . $photocount; // First Photo Class
}
?>
<img src="<?php echo JURI::root()?>images<?php echo $row->id;?>/medium/<?php echo $photos[$i]->image?>" class="<?php echo $photoclass; ?>" alt="<?php echo $photos[$i]->image_desc;?>" title="<?php echo $photos[$i]->image_desc;?>"/>
<?php
}
}
}
?>
That outputs the images correctly, however the "Photo Count" does not increase and thus each photo gets the "First Photo Class" (property_photo_main_1). I fully appreciate that the problem here is because the count is not within the loop to print each photo, but as that is directly before that image output, where is the loop, and how can I implement that the count increases?
The HTML Output is:
<img src="http://msa.eighttwentydesign.com/images/osproperty/properties/5/medium/51384100282240dc03c72cb44ce05eb9e56021d0c05.jpg" class="property_photo_main property_photo_main_1" alt="" title=""/>
<img src="http://msa.eighttwentydesign.com/images/osproperty/properties/5/medium/51384100283f9f748ca556070c2d09553298dc26d8f.jpg" class="property_photo_main property_photo_main_1" alt="" title=""/>
<img src="http://msa.eighttwentydesign.com/images/osproperty/properties/5/medium/51384100283b280e25f329d8cf1518bda4700b07765.jpg" class="property_photo_main property_photo_main_1" alt="" title=""/>
<img src="http://msa.eighttwentydesign.com/images/osproperty/properties/5/medium/51384100283c801f9afb73308c7fd77a77ea00129bb.jpg" class="property_photo_main property_photo_main_1" alt="" title=""/>
</div>
You never increment $photocount outside of that if. Also you never reset $photoclass
foreach ($photos as $photo) {
if (!empty($photo->image)) {
if (JPATH_ROOT.'/images/'.$row->id.'/medium/'.$photo->image) {
if (!isSet($photocount))
$photocount = 1;
else
$photocount++;
$photoclass = "property_photo_main property_photo_main_" . $photocount;
//HTML...
}
}
}
This way $photoclass gets reset in each iteration, also $photocount gets incremented by 1 if it has been set. I also took the liberty of using PHP's internal structures like foreach or empty, you can read about the usage in the manual.
Since JPATH_ROOT.'/images/'.$row->id.'/medium/'.$photo->image has no logic and is not null/false, it will always return true, maybe you meant to use something like file_exists?
Using !$photoclass instead of !isSet($photoclass) will throw an undefined variable notice.
I'm using WordPress and advanced custom fields, and I want to display 3-6 images depending on which fields are selected on a Select field post type.
I have it so the value/variables tie into the image name, so it would display images selected based on your choices.
e.g. "red : Red"
<img src="example.com/images/image-<?php the_field(color) ?>.jpg" alt="<?php the_field(color) ?>">
Now the noob question is, when more than one field is selected, it returns an array (i.e. red, green, black.) and I can't really have the function output as an array since it won't match the image name.
Does anyone know how to separate an array for multiple image outputs?
foreach ($image_list as $image) {
printf('<img src="example.com/images/image-%s.jpg" alt="%s" />', $image['color'], $image['color']);
}
If you don't have an associated array but just a simple array you might do:
foreach ($gem_colors as $color) {
printf('<img src="example.com/images/image-%s.jpg" alt="%s" />', $color, $color);
}
Something like:
<?php foreach($imageArray as $row): ?>
<img src="example.com/images/image-<?php echo $row['color']; ?>.jpg" alt="<?php echo $row['color']; ?>">
<?php endforeach; ?>
I have a Magento store and I would like to replace the src value of an img based on whether the referring URL contains a specific querystring or querystring value (adnetwork=as) and if not simply leave the image as it is.
Is this simple enough to do, I've searched everywhere for the answer, and even asked on various forums to no avail.
Here's what I have so far, seems like the correct syntax, just Firebug reports that it is unable to load the image URL, and it simply shows "". The paths are correct and have been tested.
<?php
// Path for default image source
$logo = $this->getSkinUrl('images/logo.gif');
// Get the referrer url from the $_SERVER array, or false if it's empty
$referrer = empty($_SERVER['HTTP_REFERER']) ? false : $_SERVER['HTTP_REFERER'];
// If the referrer exists
if($referrer) {
// parse the url for the query
$query_str = parse_url($referrer, PHP_URL_QUERY);
// If there's a query string
if(!empty($query_str)) {
// Parse it and put the array into $components
parse_str($query_str, $components);
// If the "adnetwork" component is set
if(!empty($components['adnetwork'])) {
// Set the $logo var to the adnetwork image source
$logo = $this->getSkinUrl('images/logo-no-number.gif');
}
}
}
?>
<div class="header">
<img class="shop24" src="<?php echo $this->getSkinUrl('images/shop-24.gif') ?>" alt="Shop Online 24 Hours a Day"/>
<div class="shopping-bag"><?php echo $this->getChildHtml('topcart')?></div>
<div id="fplogo"><img src="<?php echo $logo; ?>" alt="Sale Basins - Clickbasin.co.uk" /></div>
<img src="<?php echo $this->getSkinUrl('images/side_logo_promo.gif') ?>" alt="Promotion" class="side-logo-promo"/>
<?php echo $this->getChildHtml('topMenu') ?>
<?php //<?php echo $this->getLogoSrc() ?>
</div>
I hope you can help guys. Thanks.
Shouldn't you be simply echoing $logo? you are assigning the image to $logo but you never set anything to $logo.