Reputation: 341
Hello I want to disable an <img>
tag inside a certain <div>
when there's no image inputted by the user.
if(is_array($init) || is_object($init)){
foreach ($init as $data) {
echo '
<div id="profile-page-wall-post" class="card">
<div class="card-profile-title">
<div class="row">
<div class="col s1">
<img src="'.base_url('assets/images/'.$data->accounts_picture.'').'"
alt="" class="circle responsive-img valign profile-post-uer-image">
</div>
<div class="col s10">
<p class="grey-text text-darken-4 margin">'.$data->accounts_fname."\t".$data->accounts_lname.'</p>
<span class="grey-text text-darken-1 ultra-small">Shared publicly '.$data->post_date.'</span>
</div>
</div>
<div class="row center-align">
<div class="col s12">
<img class="Boxing image_attached" src="'.base_url('assets/files/'.$data->post_picture.'').'">
</div>
</div>
<div class="row">
<div class="col s12">
<p>'.$data->post_content.'</p>
</div>
</div>
<div class="row">
<div class="col s12">
<a href="'.base_url('assets/files/'.$data->post_file.'').'" download>'.$data->post_filename.'</a>
</div>
</div>
</div>
<div class="card-action row">
<div class="input-field col s8 margin">
<input id="profile-comments" type="text"
class="validate margin">
<label for="profile-comments" class="">
Comments
</label>
</div>
</div>
<div id="CommentSection" class="z-depth-1 col s12">
<div class="col s12">
<div class="card-panel grey lighten-5 z-depth-1">
<div class="row valign-wrapper">
<div class="col s2">
<img src="assets/images/def.jpg"
alt="" class="circle responsive-img">
</div>
<div class="col s10">
<p>Comment content</p>
</div>
</div>
</div>
</div>
</div>
</div>
';
}
}
I wanted to disable the <div>
with the <img>
inside, if $data->post_picture
is null. How can I do this?
Upvotes: 0
Views: 45
Reputation: 1249
Not sure why this is tagged with jQuery and Javascript, since all you seem to be using is PHP, so why don't you just:
// ... (end your echo)
';
if(!empty($data->post_picture)){
echo '
<div class="row center-align">
<div class="col s12">
<img class="Boxing image_attached" src="'.base_url('assets/files/'.$data->post_picture.'').'">
</div>
</div>
';
}
echo ' // (continue your echo)
// ...
Please also not that you may have a syntax error at "'.base_url('assets/files/'.$data->post_picture.'').'"
(you're closing and opening '' but this actually closes your echo '. You're using single quotes (') around what you're echoing, then double quotes around the img src=""
, and then single quotes around the base_url
again, which I think (I'm not sure, since the code is so messy and I get confused by all the quotes) results in a syntax error over here: '').'
.
Upvotes: 1