I am using CodeIgniter 2.2.
I have to update database with +1 every time a page is visited. Code works but it get incremented by +2 every time.
Example: if total views=2, once the page is clicked total views should be 3, but the value in the database is 4.
I am sure that I am calling the model add_one_to_view_image only once in my controller.
controller
function view(){
$view_id = $this->uri->segment(3);
if($view_id){
$this->property->add_one_to_view_image($view_id);
$prop['prop_detail'] = $this->property->get_single_property_for_view($view_id);
$prop['prop_imgs'] = $this->property->get_single_property_images($view_id);
$prop['amenities'] = $this->property->get_single_property_amenities($view_id);
$prop['latest'] = $this->home->get_latest_properties();
$size = sizeof($prop['latest']);
for($k=0; $k< $size; $k++){
$Image_name = $this->property->get_property_first_image($prop['latest'][$k]->property_id);
if($Image_name){
$prop['latest'][$k]->image=$Image_name[0]->name;
}else {
$prop['latest'][$k]->image="";
}
}
$this->load->view('property_view', $prop);
}
}
Model
function add_one_to_view_image($id){
echo "We in add one to views";
$this->db->where('property_id', $id);
$this->db->set('views', 'views+1', FALSE);
$this->db->update('property_views');
}
I added a echo statement inside the model. and it prints only once..
View
<!DOCTYPE html>
<html lang="en-US">
<head>
<?php $this->load->view('header_links'); ?>
<title><?php echo $prop_detail[0]->title; ?> | lanka Property</title>
<meta name="author" content="Sathyabaman - lankaproperty.com">
<meta name="description" content="<?php echo $prop_detail[0]->full_description; ?>">
<meta name="keywords" content="home, land, apartment, house, room, Commercial Building, buy, sell, rent, lease, sri lanka">
</head>
<body>
<div id="wrapper-outer" >
<div id="wrapper">
<div id="wrapper-inner">
<?php $this->load->view('header_top_user_bar'); ?>
<?php $this->load->view('header_logo'); ?>
<?php $this->load->view('navigation'); ?>
<!-- CONTENT -->
<div id="content"><div class="container">
<div id="main">
<div class="row">
<div class="span9">
<h1 class="page-header"><?php echo $prop_detail[0]->title; ?></h1>
<div class="carousel property">
<div class="preview">
<li class="active">
<img src="<?php echo base_url(); ?>/upload_images/<?php echo $prop_imgs[0]->name; ?>" alt="">
</li>
</div><!-- /.preview -->
<div class="content">
<a class="carousel-prev" href="#">Previous</a>
<a class="carousel-next" href="#">Next</a>
<ul>
<?php foreach ($prop_imgs as $img) : ?>
<li class="active">
<img src="<?php echo base_url(); ?>/upload_images/<?php echo $img->name; ?>" alt="">
</li>
<?php endforeach; ?>
</ul>
</div>
<!-- /.content -->
</div>
<!-- /.carousel -->
<div class="property-detail">
<div class="pull-left overview">
<div class="row">
<div class="span3">
<h2>Overview</h2>
<?php foreach ($prop_detail as $dtl) : ?>
<table>
<tr>
<?php if($dtl->status == 0){?>
<td style="font-size: 120%;"><strong>Under Approval</strong></td>
<?php } if($dtl->status == 1){?>
<td style="color:green; font-size: 200%;"><strong>Available!</strong></td>
<?php } if($dtl->status == 2){?>
<td style="color:red; font-size: 200%;"><strong>Expired!</strong></td>
<?php } if($dtl->status == 3){?>
<td style="color:red; font-size: 200%;"><strong>Deleted!</strong></td>
<?php } if($dtl->status == 4){?>
<td style="color:red; font-size: 200%;"><strong>Suspended!</strong></td>
<?php } ?>
</tr>
<tr>
<th></th>
<td><br/></td>
</tr>
<tr>
<th>Property ID :</th>
<td> PPTID<?php echo $dtl->property_id; ?></td>
</tr>
<tr>
<th>Price :</th>
<td><?php if($dtl->price == 0){ echo "negotiable"; }
else {
$price_text = (string)$dtl->price; // convert into a string
$arr = str_split($price_text, "3"); // break string in 3 character sets
$price_new_text = implode(",", $arr); // implode array with comma
echo 'Rs. '.$price_new_text.'/=';
} ?>
</td>
</tr>
<tr>
<th>Property type :</th>
<td><?php echo $dtl->type_name; ?></td>
</tr>
<tr>
<th>Property size :</th>
<td><?php echo $dtl->size; ?> <?php echo $dtl->size_type; ?></td>
</tr>
<tr>
<th>Contract type :</th>
<td><?php echo $dtl->contract_type; ?></td>
</tr>
<?php if($dtl->bed){ ?>
<tr>
<th>Bedrooms :</th>
<td><?php echo $dtl->bed; ?></td>
</tr>
<?php } if($dtl->bath){ ?>
<tr>
<th>Bathrooms :</th>
<td><?php echo $dtl->bath; ?></td>
</tr>
<?php } if($dtl->address){?>
<tr>
<th>address :</th>
<td><?php echo $dtl->address; ?></td>
</tr>
<?php } ?>
<tr>
<th>Area :</th>
<td><?php echo $dtl->area; ?></td>
</tr>
<tr>
<th>City :</th>
<td><?php echo $dtl->city; ?></td>
</tr>
<?php if($dtl->Contact_name){ ?>
<tr>
<th>Contact Name :</th>
<td><?php echo $dtl->Contact_name; ?></td>
</tr>
<?php } ?>
<tr>
<th>Contact No 1 :</th>
<td><strong><?php echo chunk_split($dtl->phone_home, 3, ' '); ?></strong></td>
</tr>
<?php if($dtl->phone_hand){ ?>
<tr>
<th>Contact No 2 :</th>
<td><strong><?php echo chunk_split($dtl->phone_hand, 3, ' '); ?></strong></td>
</tr>
<?php } ?>
<tr><td colspan="2">
<br/>
<a class="btn btn-primary btn-large list-your-property">
Contact : <?php echo chunk_split($dtl->phone_home, 3, ' '); ?></a>
</td></tr>
</table>
</div>
<!-- /.span2 -->
</div>
<!-- /.row -->
</div>
<p><?php echo nl2br($dtl->full_description); ?>.</p>
<?php endforeach; ?>
<br/><br/>
<h2>General amenities</h2>
<div class="row">
<ul class="span2">
<li class="<?php if($amenities[0]->Gym==1){echo 'checked'; }else{echo 'plain';} ?>">
Gym
</li>
<li class="<?php if($amenities[0]->Air_conditioning==1){echo 'checked'; }else{echo 'plain';} ?>">
Air Conditioning
</li>
<li class="<?php if($amenities[0]->internet==1){echo 'checked'; }else{echo 'plain';} ?>">
Internet
</li>
<li class="<?php if($amenities[0]->Wifi==1){echo 'checked'; }else{echo 'plain';} ?>">
Wifi
</li>
<li class="<?php if($amenities[0]->Lift==1){echo 'checked'; }else{echo 'plain';} ?>">
Lift
</li>
<li class="<?php if($amenities[0]->Furnished==1){echo 'checked'; }else{echo 'plain';} ?>">
Furnished
</li>
</ul>
<ul class="span2">
<li class="<?php if($amenities[0]->Television==1){echo 'checked'; }else{echo 'plain';} ?>">
Television
</li>
<li class="<?php if($amenities[0]->Hot_Water==1){echo 'checked'; }else{echo 'plain';} ?>">
Hot Water
</li>
<li class="<?php if($amenities[0]->Smoking_allowed==1){echo 'checked'; }else{echo 'plain';} ?>">
Smoking Allowed
</li>
<li class="<?php if($amenities[0]->Pets_allowed==1){echo 'checked'; }else{echo 'plain';} ?>">
Pets Allowed
</li>
<li class="<?php if($amenities[0]->Garage==1){echo 'checked'; }else{echo 'plain';} ?>">
Garage
</li>
<li class="<?php if($amenities[0]->Secure_parking==1){echo 'checked'; }else{echo 'plain';} ?>">
Secure parking
</li>
</ul>
<ul class="span2">
<li class="<?php if($amenities[0]->Swimming_Pool==1){echo 'checked'; }else{echo 'plain';} ?>">
Swimming Pool
</li>
<li class="<?php if($amenities[0]->Tennis_court==1){echo 'checked'; }else{echo 'plain';} ?>">
Tennis court
</li>
<li class="<?php if($amenities[0]->Balcony==1){echo 'checked'; }else{echo 'plain';} ?>">
Balcony
</li>
<li class="<?php if($amenities[0]->Fenced==1){echo 'checked'; }else{echo 'plain';} ?>">
Fenced
</li>
<li class="<?php if($amenities[0]->Back_up_Generator==1){echo 'checked'; }else{echo 'plain';} ?>">
Back Up Generator
</li>
<li class="<?php if($amenities[0]->Garden==1){echo 'checked'; }else{echo 'plain';} ?>">
Garden
</li>
</ul>
<ul class="span2">
<li class="<?php if($amenities[0]->Waterfront==1){echo 'checked'; }else{echo 'plain';} ?>">
Waterfront
</li>
<li class="<?php if($amenities[0]->Ocean_View==1){echo 'checked'; }else{echo 'plain';} ?>">
Ocean View
</li>
<li class="<?php if($amenities[0]->Security==1){echo 'checked'; }else{echo 'plain';} ?>">
Security
</li>
<li class="<?php if($amenities[0]->Water_Tank==1){echo 'checked'; }else{echo 'plain';} ?>">
Water Tank
</li>
</ul>
</div>
<!--
<h2>Map</h2>
<div id="property-map"></div> -->
</div>
</div>
<div class="sidebar span3">
<div class="widget contact">
<div class="title">
<h2 class="block-title">Contact Owner</h2>
</div><!-- /.title -->
<div class="content">
<form method="post" id="frm_contact_owner">
<div class="alert alert-success" id="co_sucess_message" style="display: none">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Message successfully send to owner!. <br/>Thank you!</strong>
</div>
<input type="hidden" name="co_property_id" value="<?php echo $dtl->property_id; ?>">
<div class="control-group">
<label class="control-label" >
Name
<span class="form-required" title="This field is required.">*</span>
<span class="form-required" id="co_name_error" title="This field is required."></span>
</label>
<div class="controls">
<input type="text" name="co_name" id="co_name">
</div><!-- /.controls -->
</div><!-- /.control-group -->
<div class="control-group">
<label class="control-label" >
Email
<span class="form-required" title="This field is required.">*</span>
<span class="form-required" id="co_email_error" title="This field is required."></span>
</label>
<div class="controls">
<input type="text" name="co_email" id="co_email">
</div><!-- /.controls -->
</div><!-- /.control-group -->
<div class="control-group">
<label class="control-label" >
Message
<span class="form-required" title="This field is required.">*</span>
<span class="form-required" id="co_message_error" title="This field is required."></span>
</label>
<div class="controls">
<textarea name="co_message" id="co_message"></textarea>
</div><!-- /.controls -->
</div><!-- /.control-group -->
<div class="form-actions">
<input type="submit" id="co_send" class="btn btn-primary arrow-right" value="Send">
<img id="co_ajax_image" src="<?php echo base_url(); ?>html/assets/img/ajax_loader.gif" alt="" style="float: left; display:none">
</div><!-- /.form-actions -->
</form>
</div><!-- /.content -->
</div><!-- /.widget -->
<div class="widget properties last">
<div class="title">
<h2>Latest Properties</h2>
</div><!-- /.title -->
<div class="content">
<?php foreach ($latest as $latest_pro) :?>
<div class="property">
<div class="image">
<?php
if($latest_pro->image){
$image_name = base_url().'upload_images/'.$latest_pro->image;
}else{
$image_name = base_url().'html/assets/img/tmp/property-small-5.png';
}
?>
<img src="<?php echo $image_name; ?>" alt="">
</div><!-- /.image -->
<div class="wrapper">
<div class="title">
<h3>
<?php echo substr($latest_pro->title, 0, 16); ?>..
</h3>
</div><!-- /.title -->
<div class="location"><?php echo $latest_pro->area; ?>, <?php echo $latest_pro->city; ?></div><!-- /.location -->
<div class="price">
<?php if($latest_pro->price == 0){ echo "negotiable"; }
else {
$price_text = (string)$latest_pro->price; // convert into a string
$arr = str_split($price_text, "3"); // break string in 3 character sets
$price_new_text = implode(",", $arr); // implode array with comma
echo 'Rs. '.$price_new_text.'/=';
} ?>
</div><!-- /.price -->
</div><!-- /.wrapper -->
</div><!-- /.property -->
<?php endforeach; ?>
</div><!-- /.content -->
</div><!-- /.properties -->
</div>
</div>
</div>
</div>
</div><!-- /#content -->
</div><!-- /#wrapper-inner -->
<?php $this->load->view('footer'); ?>
</div><!-- /#wrapper -->
</div><!-- /#wrapper-outer -->
<?php $this->load->view('footer_setting_palette'); ?>
<?php //$this->load->view('property_filter_ajax'); ?>
<?php $this->load->view('say_hello_ajax'); ?>
<?php $this->load->view('property_contact_owner'); ?>
</body>
</html>
I know it's completly illlogical but check this out....
I had also got the same issue long back but after 1 week of headache I come to know about this solution.
I got the solution from this link, check out the 2nd answer. Initially I also didn't take that solution seriously but in the end it worked for me :)
Solution :
Make sure you don't have tag with empty src="" attribute or any css style refering to empty url (like background: url();) on your site around the place when you have your code that runs twice.
try this solution, i have also done this same in my project and didn't face any problem. if i see logically there is no problem with your code but just try row() instead of result() function and than see if it have the same impact. and make sure default value of the column view is 0
function add_one_to_view_image($id){
$this->db->select('views');
$this->db->from('property_views');
$this->db->where('property_id', $id);
$pag = $this->db->get();
$resultset = $pag->row();
$newvalue = ++$resultset->views;
$data = array('views' => $newvalue);
$this->db->where('property_id', $id);
$this->db->update('property_views', $data);
}
when you are going to get 1 row is bettery to get it by row rather than getting it as a result.
Regards
You can make the incrementation directly in active record :
Refering to the documentation :
set() will also accept an optional third parameter ($escape), that
will prevent data from being escaped if set to FALSE.
So the views+1will not be escaped and the query will work correctly :
function add_one_to_view_image($id){
$this->db->where('property_id', $id);
$this->db->set('views', 'views+1', FALSE);
$this->db->update('property_views');
}
Check your webserver access log. My guess is that you're calling your page twice... Either from a bad link (empty src), redirect to it on a 404 (missing favicon?) or something similar.
I've got the same problem when i'm making a view counter it's getting incremented multiple times.
then i came up with the solution to use $this->db->cache_delete_all();
function add_one_to_view_image($id){
$this->db->cache_delete_all();
$this->db->where('property_id', $id);
$this->db->set('views', 'views+1', FALSE);
$this->db->update('property_views');
}
But in my senario i was using direct query eg:
$this->db->query("Update settings set option_value = '{$newCounter}' where option_name = 'counter'");
Hope it will fix your problem.
Related
I'm currently working on the forum section of my website.
I followed the link #CBroe suggest me on the comments and implemented offcanvas for my previous problem and now I have this:
<table class="table is-indent changes" id="newsTable">
<thead>
<th></th>
<th></th>
</thead>
<tbody>
<?php foreach($fetchNews as $data):
echo '<tr class="trNew btnSelect" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight" id=\''.$data['id'].'\'>' ?>
<td class="cell-60 responsive-hide" style="width: 100px;">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
</td>
<td id="<?php echo $data['id']; ?>">
<input type="hidden" id="idNew" value="<?php echo $data['id']; ?>" data-value="<?php echo $data['id']; ?>">
<div class="content">
<div class="title" id="title"> <?php echo $data['titolo']; ?> </div>
<div class="metas">
<span class="author"><?php echo $data['autore']; ?> - </span>
<span class="data"><?php echo $data['data']; ?></span>
</div>
</div>
<?php endforeach;?>
</td>
</tr>
</tbody>
</table>
And this is the offcanvas the table below open:
<!--PANEL NEWS-->
<?php foreach($fetchNews as $data):?>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h1 id="newsTitolo"><?php echo $data['titolo']??''; ?></h1>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="forum-header">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
<span class="name"><?php echo $data['autore']??''; ?></span>
<span class="time"><?php echo $data['data']??''; ?></span>
</div>
<div class="forum-content">
<div id="newsTesto" class="articolo">
<?php $Parsedown = new Parsedown();
echo $Parsedown->text(file_get_contents('post/'.$data['titolo'].'/'.$data['titolo'].'.txt')??''); ?>
</div>
<p> <?php echo $data['allegato']??'';?></p>
</div>
</div>
</div>
<?php endforeach;?>
<!--END PANEL NEWS-->
What I basically need to do is display the article with the same ID as the title on the table as this example image: table & panel that by clicking on the first title (ahaaa) it opens the corresponding article.
I tried some stuff like adding $data['id'] on both data-bs-target and data-bs-toggle of the and as id of the offcanvas but it didnt work
I have to following php code where I want to execute the image function if there is an image to show. Which means If the image field is empty/NULL I dont want to show the image, because it will give an error saying 'no image found'.
How can I do this?
Thanks in advance.
<div>
<?php if (!empty($datas[0]['imgProduct1'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct1']);?>" class="img-fluid" alt="Product1" />
<?php } ?>
</div>
<div>
<?php if (!empty($datas[0]['imgProduct2'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct2']);?>" class="img-fluid" alt="Product2" />
<?php } ?>
</div>
<div>
<?php if (!empty($datas[0]['imgProduct3'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct3']);?>" class="img-fluid" alt="Product3" />
<?php } ?>
</div>
<div>
<?php if (!empty($datas[0]['imgProduct4'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct4']);?>" class="img-fluid" alt="Product4" />
<?php } ?>
</div>
(Goes till imgProduct8)
In the Database image, I have my picture data ready. In the last line you see imgProduct1 filled, imgProduct2 filled, imgProduct3 filled. After that imgProduct4 is NULL, so I dont want to execute the image function for that matter.
Database image:
In Result from the database picture, you see the result I am getting. So again imgProduct1, imgProduct2 and imgProduct3 are filled with a link, imgProduct4, imgProduct5 etc are not. So I dont want to show the image, thats not there.
Result from database:
The result I am getting now is 3 pictures in my slide show and after that just blank pictures. So he is still think there are more pictures to show.
my whole code:
<?php
require('../php/connection.php');
$product = $_GET['product'];
$sql = "SELECT * FROM tblproduct WHERE strProductNaam='$product'";
$result = sqlsrv_query($conn,$sql);
if( $result === false ) {
die( print_r( sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$datas[] = $row;
}
echo '<pre>';
print_r($datas);
echo '</pre>';
sqlsrv_free_stmt($result);
sqlsrv_close($conn);
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Home Gym</title>
<?php
include('../structure/effects.php');
?>
</head>
<body>
<!-- Header -->
<?php
include('../structure/header.php');
?>
<!-- /Header -->
<!-- Main -->
<main>
<br>
<!-- Product Section -->
<section class="single-product">
<div class="container">
<div class="row">
<div class="col-md-5">
<div class="container-fluid p-0">
<div class="site-slider">
<div class="slider-one">
<div>
<?php if (!empty($datas[0]['imgProduct1'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct1']);?>" class="img-fluid" alt="Product1" />
<?php } ?>
</div>
<div>
<?php if (!empty($datas[0]['imgProduct2'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct2']);?>" class="img-fluid" alt="Product2" />
<?php } ?>
</div>
<div>
<?php if (!empty($datas[0]['imgProduct3'])){ ?>
<img src="<?php echo ($datas[0]['imgProduct3']);?>" class="img-fluid" alt="Product3" />
<?php } ?>
</div>
<div>
<?php if (($datas[0]['imgProduct4']) !== NULL){ ?>
<img src="<?php echo ($datas[0]['imgProduct4']);?>" class="img-fluid" alt="Product4" />
<?php } ?>
</div>
<div>
<?php if (($datas[0]['imgProduct4']) !== NULL){ ?>
<img src="<?php echo ($datas[0]['imgProduct5']);?>" class="img-fluid" alt="Product5" />
<?php } ?>
</div>
<div>
<?php if (($datas[0]['imgProduct4']) !== NULL){ ?>
<img src="<?php echo ($datas[0]['imgProduct6']);?>" class="img-fluid" alt="Product6" />
<?php } ?>
</div>
<div>
<?php if (($datas[0]['imgProduct4']) !== NULL){ ?>
<img src="<?php echo ($datas[0]['imgProduct7']);?>" class="img-fluid" alt="Product7" />
<?php } ?>
</div>
<div>
<?php if (($datas[0]['imgProduct4']) !== NULL){ ?>
<img src="<?php echo ($datas[0]['imgProduct8']);?>" class="img-fluid" alt="Product8" />
<?php } ?>
</div>
</div>
<div class="slider-button">
<span class="prev position-top"><i class="fas fa-chevron-left"></i></span>
<span class="next position-top right-0"><i class="fas fa-chevron-right"></i></span>
</div>
</div>
</div>
</div>
<div class="col-md-7">
<p class="new-arrival text-center">NEW</p>
<div class="product-bottom">
<p><i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</p>
<p><h3><?php echo ($datas[0]['strProductNaam']); ?></h3></p>
<p class="price"><h5><s>€<?php echo ($datas[0]['intPrijs']); ?></s> <b><span class="make_red">€<?php echo ($datas[0]['strSalePrijs']); ?></span> </b></h5></p>
<p><b>Availability: </b>In Stock</p>
</div>
<div class="positive">
<p><i class="fa fa-plus" aria-hidden="true"></i> <?php echo ($datas[0]['strPlusPunt1']); ?></p>
<p><i class="fa fa-plus" aria-hidden="true"></i> <?php echo ($datas[0]['strPlusPunt2']); ?></p>
</div>
<div class="negative">
</div>
<label>Quantity: </label>
<input class="text-center" type="text" value="1"></input>
<button type="button" class="btn btn-primary">Add to Cart</button>
<table class="content-table">
<thead>
<tr>
<th>Product Specifications</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Type</td>
<td><?php echo ($datas[0]['strSpecSoort']); ?></td>
</tr>
<tr class="active-row">
<td>Guarantee</td>
<td><?php echo ($datas[0]['strSpecGarantie']); ?></td>
</tr>
<tr>
<td>Material</td>
<td><?php echo ($datas[0]['strSpecMateriaal']); ?></td>
</tr>
<tr class="active-row">
<td>Weight</td>
<td><?php echo ($datas[0]['strGewicht']); ?></td>
</tr>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<!-- /Product Section -->
<!-- Product Description -->
<section class="product-description">
<div class="container">
<h6>Product Description</h6>
<p><?php echo ($datas[0]['strBeschrijving']); ?></p>
</div>
</section>
<!-- /Product Descriptionn -->
<br>
<hr class="hr">
<!-- On Sale Product -->
<?php
include('../product-sale.php');
?>
<!-- /On Sale Product -->
</main>
<!-- /Main -->
<!-- Footer -->
<?php
include('../structure/footer.php');
?>
<!-- /Footer -->
<!-- Script: Bootstrap CDN, JS -->
<?php
include('../structure/script.php');
?>
</body>
</html>
you can try updating the query:
SELECT * FROM table_name WHERE image_column != NULL
Hope so it might help you. It would be better if you provide the whole code...
SOLVED:
<?php if (!empty($datas[0]['imgProduct1'])){ ?>
<div>
<img src="<?php echo ($datas[0]['imgProduct1']);?>" class="img-fluid" alt="Product1" />
</div>
<?php } ?>
The div had to be inside of the if function. That's why a white screen popped up.
I'd like to include an IF statement into my highlights.phtml file where I can check if my custom attribute (named preorder) has been selected or not. As the name indicates, this custom attribute can be set on a product to signify if it can be pre-ordered. How can I access this variable/attribute in the highlights slider code, below? It doesn't seem to be part of the $products array?
<?php $products = $this->getHighlightedProducts() ?>
<?php if (is_array($products) && count($products)): ?>
<div class="block block-related">
<div class="block-title">
<h2><?php echo $this->__('Highlighted Products') ?></h2>
</div>
<div class="block-content">
<div class="product-carousel">
<div class="product-carousel">
<ul class="highlighted-products-slider slider">
<?php $limit = 6; ?>
<?php foreach ($products as $product): ?>
<li class="item">
<div class="product" >
<a class="product-image" href="<?php echo $this->escapeHtml($product['url']) ?>">
<img src="<?php echo $this->escapeHtml($product['image']) ?>">
</a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($product['name']) ?>
</p>
<?php echo $product['price'] ?>
</div>
<div class="actions">
<a href="<?php echo $this->escapeHtml($product['add_to_cart_url']) ?>">
<button class="button btn-cart"><?php echo $this->__('Add to Cart') ?></button>
</a>
</div>
</div>
</li>
<?php
if(++$ct >= $limit)
break;
?>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
</div>
</div>
</div>
Get the attribute with the code i added, then use it for your logic. What you want to do with the attribute, you can do now. But $product['id'] has to exist!
You need the product id for this to work, else maybe the SKU.
Hope to help.
<?php $products = $this->getHighlightedProducts() ?>
<?php if (is_array($products) && count($products)): ?>
<div class="block block-related">
<div class="block-title">
<h2><?php echo $this->__('Highlighted Products') ?></h2>
</div>
<div class="block-content">
<div class="product-carousel">
<div class="product-carousel">
<ul class="highlighted-products-slider slider">
<?php $limit = 6; ?>
<?php foreach ($products as $product): ?>
<?php
$productToCheck= Mage::getModel('catalog/product')->load($product['id']);
//use this variable
$variable = $productToCheck->getData('preorder');
//use this variable when attribute is a dropdown
$variableIfItsADropdown = $product->getAttributeText('preorder');
?>
<li class="item">
<div class="product" >
<a class="product-image" href="<?php echo $this->escapeHtml($product['url']) ?>">
<img src="<?php echo $this->escapeHtml($product['image']) ?>">
</a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($product['name']) ?>
</p>
<?php echo $product['price'] ?>
</div>
<div class="actions">
<a href="<?php echo $this->escapeHtml($product['add_to_cart_url']) ?>">
<button class="button btn-cart"><?php echo $this->__('Add to Cart') ?></button>
</a>
</div>
</div>
</li>
<?php
if(++$ct >= $limit)
break;
?>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
</div>
</div>
</div>
<?php
//Start a session
if(!isset($_SESSION)){
session_start();
}
if($_SESSION['email_address']==""){
$msg=base64_encode("Please Login");
header("Location:../../index.php?msg=$msg");
exit();
}
?>
<?php
require"../db/db_connection.php";
$_GET['email_address']=$_SESSION['email_address'];
date_default_timezone_set("Asia/Colombo");
$stime = date('Y-m-d H:i:s');
$sql = "SELECT c.course_name,c.course_id,su.subject_name,su.subject_id,ex.exam_paper_name,ex.exam_paper_id,ex.date_posted,ex.deadline FROM student s LEFT JOIN course c ON s.course_id=c.course_id LEFT JOIN subject su ON su.course_id=c.course_id LEFT JOIN exam_paper ex ON ex.subject_id=su.subject_id WHERE s.email_address='".$_SESSION['email_address']."' AND ex.status=1";
$query = mysqli_query($con,$sql);
?>
<html>
<head>
<meta charset="UTF-8">
<title>ITech Institute</title>
<link rel="stylesheet" type="text/css" href="../../css/admin_style.css">
<meta name="viewport" content="width=device-width,initial-scale: 1.0, user-scalabe=0" />
<link rel="stylesheet" type="text/css" href="../../font-awesome-4.6.3/font-awesome-4.6.3/css/font-awesome.css">
<script src="../../js/jquery.min.js"></script>
<script src="../../js/admin.js"></script>
<!-- For nice scroll start-->
<script src="../../js/jquery.nicescroll.js"></script>
<script src="../../js/style.js"></script>
<!-- nice scroll end-->
<!-- clock start-->
<script src="../../js/clock.js"></script>
</head>
<body>
<?php
include("../../include/internal_header.php");
?>
<!-- <div id="header">
<div class="logo"> Admin<span> Page</span></div>
</div>-->
<a class="mobile" href="#">MENU</a>
<div id="container">
<div class="sidebar">
<ul id="accordion" class="accordion" style="margin:0; padding:0;">
<li>
<div class="link"><i class="fa fa-dashboard"></i>Dashboard</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>Profile</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>View Courses</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>View Subjects</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>Exam</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>View Result</div>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>Log Out</div>
</li>
<li>
<div class="link"><form name="clock"><font color="white"><i class="fa fa-clock-o"></i>Time: <br></font> <input style="width:150px;" type="submit" class="trans" name="face" value="">
</form>
</div>
</li>
</ul>
</div><!--sidebar-->
<div class="content">
<div class="content_heading">
<p>View Exams</p>
</div><!--content_heading-->
<div class="div1">
<!--table start-->
<table>
<tr>
<td>Course Name</td>
<td>Subject Name</td>
<td>Exam Paper Name </td>
<td>Data Posted Name</td>
<td>Dead Line</td>
<td>Start Exam</td>
</tr>
<tr><?php while($row = mysqli_fetch_array($query)){ ?>
<td><?php echo $row["course_name"]; ?></td>
<td><?php echo $row["subject_name"]; ?></td>
<td><?php echo $row["exam_paper_name"]; ?></td>
<td><?php echo $row["date_posted"]; ?></td>
<td><?php echo $row["deadline"]; ?></td>
<td>
<a target="_blank" title="Start Exam" href="start_exam_paper.php?stime=<?php echo $stime;?>&exid=<?php echo $row['exam_paper_id'];?>&cid=<?php echo $row['course_id'];?>&suid=<?php echo $row['subject_id'];?>"style="visibility:<?php echo $_SESSION["Visibility"]; ?>">
<button id="btn-st">
<i class="fa fa-edit"></i> Start Exam
</button>
</a>
</td>
</tr>
<?php }?>
</table>
</div><!--div1-->
</div>
</div><!--div1-->
</div><!--content-->
</div><!--container-->
</body>
</html>
this is my code i need to disable the Start Exam button after the click.and student can't re-logging and click the button again, my system in examination system. i use the js but it's not work properly. so i need to validate to php
You can save student details into session after login. if session has value then use this condition in you php file:
if(!empty($_SESSION)){
echo ""; // Don't put here your login button.
}else{
echo " Your login button"; // Put here your login button.
}
I want to change the color of the div of this table (all records that status = no in the database ),Which means unread message should have a different div class. I have no idea how to do this i am using codeigniter as my framework
My view
<div class="row">
<div class="span10 box" style="padding: 10px;">
<?php echo form_open('admin/messages'); ?><!-- start of the form -->
<p>Recent Messages</p>
<table class="table hovered">
<thead>
<tr class="selected">
<th class="text-left">Name</th>
<th class="text-left">Email</th>
<th class="text-left">Phone</th>
<th class="text-left">Message</th>
</tr>
</thead>
<tbody>
<?php
if(isset($records)) :
foreach($records as $row) :
?>
<tr>
<td class="right"><?php echo $row->contactus_name; ?></td>
<td class="right"><?php echo $row->contactus_email; ?></td>
<td class="right"><?php echo $row->contactus_phone; ?></td>
<td class="right tertiary-text-secondary text-justify"><?php echo $row->contactus_comment; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot></tfoot>
</table>
<?php else : ?>
<p>No records</p>
<?php endif; ?>
</div>
<div class="span3">
<nav class="sidebar dark">
<ul>
<li>
<a href="#">
<i class="icon-home"></i>
Inbox <strong>
<?php if(isset($count)){echo '<div class="brand"><div class="badge bg-red">'.$count.'</div></div>';}?>
</strong>
</a>
</li>
<li>
<a href="#">
<i class="icon-home"></i>
Send
</a>
</li>
<li>
<a href="#">
<i class="icon-home"></i>
Newsletter/Ad
</a>
</li>
</ul>
</nav>
</div>
<?php echo form_close(); ?><!-- END of the form -->
</div>
Providing a link to / your code would allow us to give far more specific advice, but in general:
<?php if ($foo == 'bar') { $class_name = 'class1'; } else { $class_name = 'class2'; } ?>
<div class="<?php echo $class_name; ?>">
foreach($results as $row)
{
echo '<div '. ($row->read == 0 ? ' class="unread"': '') .'>Your content</div>';
}