Not showing a picture where table field is empty - php

I have a MTSQL database where up to 25 images can be stored, in table fields called picture1 through to picture 25.
What i want to do is check these variables once they are pulled from the database to see whether they should be displayed or not.
currently if there isn't an images it still shows and you just get the missing image sign. And no matter what i seem to write it shows regardless off if there is an image or not, below is my current code.
<? if(!isset($picture2) || empty($picture2)){ ?
<div class="property-slide">
<a href="m/properties/<?php echo $row['picture2']; ?>" class="image-popup">
<img alt="" src="m/properties/<?php echo $row['picture2']; ?>"></a>
</div>
<? } ?>
The value of picture 2 is currently just 1.jpg which is located in a folder on the server at the path m/properties/.
I did consider storing all the images seperatley, which would be easier as i could use a query to show all relevant properties, but this was pre built by somebody else and the database is populated from a third party api.

Related

Display a column integrated in an echo and html

I am stuck with an issue here. I am trying to read out a column (pdf) from my mysql db by php and show it on the website as a link. the column's value are pdf names of files saved on the ftp and i want to display it as a link on the page.
<?
$rs_news=mysql_query("SELECT * FROM news WHERE ueberschrift_$lang NOT LIKE '' ORDER BY id DESC");
if(mysql_num_rows($rs_news)>=1){
?>
<? for($i=0;$i<mysql_num_rows($rs_news);$i++){ ?>
<h4 <? if($i>=1){echo("style='margin-top:24px;'");} ?>>
<?= mysql_result($rs_news,$i,"ueberschrift_$lang"); ?></h4>
<img src="../news/bilder/<?= mysql_result($rs_news,$i,"userfile_1"); ?>" onerror="this.style.display='none';" style="padding-top:3px; padding-right:7px;" width="150px" height="110px" align="left"></img>
<?= mysql_result($rs_news,$i,"langtext_$lang"); ?><br><br><br>
Test
<? } ?>
<? } ?>
I know my coding might be ugly, I am very new to PHP and trying to do simple things but I guess I think too complicated.
I have a DB with rows where SOME have a PDF value and some dont.
What I want is that at displaying it only picks those which have a PDF value and displays it via echo like this:
Test
The default value in the column pdf is NULL, I tried to do it via if empty but didnt succeed.
Please let me know if you have any solution for this.
Thanks.
K.

Passing segment data from view to controller and then to a new view

Hi i am using Codeigniter(i am fairly new) and i have a problem displaying data(actually a path from the database) to View B but lets take it from the beggining. I am making a cinema web page and I want a user to click on a link and then get the appropriate redirect to another link which will display the movie that clicked. I am getting the movie name from the database and manage to send it to the Controller B as a parameter and get the image path that i want to display in order to show the picture. But the web page does not show the picture although the path is already sent(i have checked it on Firefox fire bug and to a blank page just to make sure the the path is sent) Btw when i load the page the method and parameter appears on the url but when i delete the parameter and the method from the url and hit enter the path works perfectly displaying the image. Any help?
ps I am a rookie
This is from view a
<div class="movie__images">
<a href="<?php echo base_url()?>movie_page_full/get_user_click_info/<?php echo $movie_data[6]->title ?>" class="movie-beta__link">
<img alt='' src=<?php echo $now1 ?>>
</a>
</div>
This is from controller b
public function get_user_click_info(){
$this->load->model('movie_page_full_model');
$decoded_movie_name = $this->uri->segment(3);
$query_data = $this->movie_page_full_model->get_single_movie_data($decoded_movie_name);
$data['path'] = $query_data[0]->path;
$this->load->view('templates/header');
$this->load->view('Home/view_movie_page_full',$data);
$this->load->view('templates/footer_movie_page_full');
}
This is from the view b where i send the path from the controller b
<div class="col-sm-4 col-md-3 movie-mobile">
<div class="movie__images">
<img alt="" src=<?php echo $path ?>>
</div>
</div>
A proof that the path is send to the HTML code but does not show it
The url (Gravity is the name of the movie)
I found the answer to my question. I discovered that when i was changing controllers and loading the image, the path was displaying properly but actually it was missing the full url as i was leaving from the homepage that i set as the base url so the only thing that i had to do, was to use the variable that contains the path inside the codeigniter base url. Base url actually appends the rest of missing part. Below is the correct code block.
<div class="col-sm-4 col-md-3 movie-mobile">
<div class="movie__images">
<img alt="" src=<?php echo base_url($path)?>>
</div>
</div>

image wont show using an id from database

Hi i am trying to get an image to display when a result is picked from a data base this is my code below:
$box .= '<div style="margin-top:10px;height:120px;"id=\"Video\">
<br/>
<div style="border-style:solid;border-width:1px;border-color:#00000;width:400px;float:right;"id=\"Title\">'.$row['title'].'</div>
<div style="width:220px;height:150px;float:left;border-style:solid;border-width:1px;border-color:#000000;" id=\"VideoImage\">"
<img class="partimg1" src="classroom/images/'.$row['media_id'].'.jpg" /></div>
<div style="height:50px;width:400px;float:right;padding:2px;margin-bottom:5px;" id=\"Blurb\">'.$row['blurb'].'</div>
<div style="height:21px;width:152px;margin-top:45px;margin-left:7px;background:url(images/bg_top_img2-09.jpg) repeat-x;color:#ffffff;padding-left:2px;float:left;border:1px solid #000000;position:relative;border-radius:15px;text-align:center;" id=\"Downloads\"> Download </div>
</div>';
the line with in the middle is where the image should be the .$row['media_id']. this will be a value from the database it will only be a number so for example 1 up to 50 and in the images folder the images are named 1 to 50 and they are all JPG is there something that i have missed because i have used this before and it worked.
all that displays on the screen is a broken image link like when the web page cannot find the image in the folder.
any help would be much appreciated.
You break the src link.
src=\"classroom/images/'.$row['media_id'].'.jpg\"/>
As you use simple quote ' for string delimiter, you don't need to escape double ones "
<img class=\"partimg1\" src=\"classroom/images/"'.$row['media_id'].'".jpg\"/>
Should be
<img class="partimg1" src="classroom/images/'.$row['media_id'].'.jpg" />
You also need to fix all your id attributes

custom background image for every WordPress page?

i am trying to have different header background images depending on which inner page is accessed. Right now i have the same picture for all inner pages and need the php code changed so its conditional. Like if im on contact page, 1.jpg to be set as header img. If on services page, 2.jpg to be set as header img etc, you get the idea.
Here is the php code ive found in this wp theme im trying to improve for a friend:
<div class="bgtop">
<?php
//display featured image if one exists
$featimage = get_bloginfo('stylesheet_directory') . "/images/pageheader.png";
if ((has_post_thumbnail( $post->ID ))&&(!is_single()&&(!is_category())) ){
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
$featimage = $image[0];
}
?>
<div class="pageheader" style="background: url(<?php echo $featimage; ?> ); background-position: center top;">
<div class="centermenu">
<div class="pagelogo">
<!--<a href="<?php bloginfo('home'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/indexlogo.png" alt="logo" />
</a>-->
</div>
Well.. It's more of a structure thing. How are you determining which page they are on? Does the user click a link? Use the information available to the server to decide what content to serve. If you're using one script to serve all your pages, then you'll need to pass it a parameter when the user clicks a link. You can do this by making your links take parameters.
Markup like so:
<a href='default.php?page=home'> Navigate To Home </a>
<a href='default.php?page=blog'> Navigate To Blog </a>
php like so:
if($_POST['page'] == "home")
echo $homeheader;
elseif($_POST['page'] == "blog")
echo $blogheader;
But, usually you just make multiple php pages that include some common elements (called templating). That helps keep things cleaner than making one php script that serves up your whole site.
If you're wanting the manage this in the back-end of WordPress: You can use the Advanced Custom Fields Plugin for WordPress (http://wordpress.org/plugins/advanced-custom-fields/). Through it, you can add a field on every page an even every post that allows you to enter in a background image.
Then, in your header.php template file, add the shortcode somewhere in your body tag:
<body background="(<?php the_field('background_image')" ?>)">
Depending on what page you're on, it will show that background image.
If You'd like the process automated: You can create a folder called "bg" and have an image with the same name as your page. For example, for about.php you can have about.jpg.
Then write a script that takes the page name, and then sets the background image to that name. You would place this in the header.php file in your template Something like:
$page = end(explode("/",$_SERVER['REQUEST_URI']));
$image = str_replace("php","jpg",$page);
Then use:
<body background="bg/<?php print $image ?>">
This is assuming that you are keeping your image files in http://www.yoursite.com/bg/ But you can also use shortcodes to keep these images within your theme with <?php echo get_template_directory_uri(); ?>

Modx Gallery Error

I have a portfolio page with small boxes with a image and link.
This seems (after struggling in code) to work, but the image don't work.
For each porject on the portfolio page:
[[!Gallery? &album=`[[+tv.gallery]]` &limit=`1` &thumbWidth=`870` &thumbHeight=`400` &thumbZoomCrop=`2` &toPlaceholder=`projecten`]]
<li class="[[dynamicWidget]]" id="[[+tv.category]]">
[[!+projecten:notempty=`
<div class="item">
<a href="[[~[[+id]]]]" title="[[+description]]">
<img src="[[+projecten.image]]" alt="[[+description]]" />
</a>
</div>
`]]
</li>
( i'm using the default gallery function)
thetv.gallery is the id of the gallery wich i like to use, but now i takes only the first album, not the first picture of a project.
It works, but only the selected image is not the album's first item (tv.gallery) but the first or second image in that album.
So:
- i have 2 pages with each a gallery witht to images
- the code gives me the first album with picture 1 and picture 2.
How to solve this, please give me some advice because i really want this script to be finished. thanks
Not sure if I understood exactly what you want to do, but maybe you should be using the GalleryAlbums snippet in this case, in combination with the albumCoverSort option.
edit: based on your comment, it looks like Gallery might be the best choice:
[[!Gallery? &album=`myProject` &limit=`1` &sort=`rank`]]
Refer to the docs for more info about how to sort the thumbnail shown.

Categories