Actually I am working on the 2002 ( old php project) based on the requirement. So my work is to show the difference between events markers based on the dates by placing some width dynamically in php. So I wrote the code after that it is not even displaying the events markers in the page.
I will provide the code which I wrote for this requirement.
function getEvents($uid)
{
$timeLineQry = mysql_query("select * from timelines where user_id = $uid and status=1 order by id desc");
if(mysql_num_rows($timeLineQry) > 0)
{
$data='';
while($tres = mysql_fetch_assoc($timeLineQry))
{
$data.='<div class="events-chat" id="timeline'.$tres['id'].'">
<button class="btn btn-success" onclick="addEvent('.$tres['id'].')"> Add Event</button>
<div id="" style="float:right;">
<span style="margin-left: 10px;color: #696767;
cursor: pointer;margin-right: 25px;font-size: 16px;font-weight: bolder;font-family: inherit;" onclick="getTimeLine(\''.$tres['title'].'\',\''.$tres['description'].'\',\''.$tres['id'].'\')">'.$tres['title'].'</span>
<i class="glyphicon glyphicon-trash" onclick="deleteTimeline('.$tres['id'].')"></i>
</div>
<div style="clear:both;margin-bottom:35px;"></div>
<div id="eventBlck'.$tres['id'].'">';
//echo "select * from events where user_id = $uid and timeline=".$tres['id'];exit;
$user_exe1 = mysql_query("select * from events where user_id = $uid and timeline=".$tres['id']." order by date asc");
if(mysql_num_rows($user_exe1) > 0) {
$i=1;
$data.='<div class="events-chat-inner">
<div class="all-cht-blk">
<div class="event-border">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div>
';
while($res = mysql_fetch_assoc($user_exe1))
{
//Here is the code I just tried to subtract the date of one event from date of another event.
$datecount = count($res['date']);
for($j = 0; $j <= $datecount; $j++){
$previous_event_date = strtotime($res['date'][j]);
$present_event_date = strtotime($res['date'][j+1]);
$distance = $previous_event_date - $present_event_date;
$distance = floor($distance/(60 * 60 * 24));
$case1 = range(0,20);
$case2 = range(1,40);
if(in_array($distance,$case1))
{
$distancestyle = 'width:130px';
}
elseif(in_array($distance,$case2))
{
$distancestyle = 'width:180px';
}
else
{
$distancestyle = 'width:230px';
}
if($i%2==0){$bc='#f45e34';}else if($i%3==0){$bc='#fa454a';}else if($i%4==0){$bc='#3cb54b';}else if($i%5==0){$bc='#03aeac';}else{$bc='#9f388b';}
if($i%2==0)
{
$data.='<div class="event-ct-blk" style='\$distancestyle\'>
<h3 onclick="getData('.$res['id'].',
\''.str_replace("'","\'",$res['name']).'\',
\''.str_replace("'","\'",$res['description']).'\',
\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
<p onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
<div class="pointer">
<div class="c-dot"></div>
<div class="p-strip-2" style="height:125px;"></div>
<div class="q-circle-outer" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
<div class="q-circle" style="background: '.$bc.';"></div>
</div>
<div class="p-strip" style="height:25px;"></div>
<div class="c-dot"></div>
</div>
<p class="q-date" onclick="getData('.$res['id'].',
\''.str_replace("'","\'",$res['name']).'\',
\''.str_replace("'","\'",$res['description']).'\',
\''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
</div>';
}
else
{
$data.='<div class="event-ct-blk" style='\$distancestyle\'>
<h3 onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
<p onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
<div class="pointer">
<div class="c-dot"></div>
<div class="p-strip" style="height:25px;"></div>
<div class="q-circle-outer" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
<div class="q-circle" style="background: '.$bc.';"></div>
</div>
<div class="p-strip-2" style="height:125px;"></div>
<div class="c-dot"></div>
</div>
<p class="q-date" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
</div>';
}
$i++;
}
$data.='</div></div>';
}
else
{
$data.='<div class="event-border" style="width:96%;">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div>';
}
$data.='</div></div>';
}
}
else
{
$data='<div class="events-chat" id="timeline1"> <button class="btn btn-success" onclick="addEvent(1)"> Add Event</button><div style="clear:both;margin-bottom:35px;"></div><div id="eventBlck1"> <div class="event-border" style="width:96%;">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div></div></div>';
}
}//end for loop
return $data;
}
In this code I place the code which I marked as the comments and actually this is the code I have present but after working on this file events are not showing canyou please see the issue in this code or any errors.
I am creating a seat reservation system. In my system, the code check number of seats a bus contains then pass it inside a for loop. When a user pick 2 passengers, it means two seats will be booked. How can I validate the checkbox in the for loop depending on the number of passenger(s) selected.
Using the GUI for more explanation.
on the main page, 2 there indicates number of passenger(s) selected.
When you come to the second page where the values are passed to, you can see 2 Adults as the selected number of passengers. When you click on Submit Button it does not validate the checkbox based on the number of passenger(s) selected. And if I should put required in the checkbox it validates the whole checkbox since it is in a loop
$_SESSION['seat_no'] is the number of seat(s) a bus contains. Let assume a user that want to book a seat selected two passengers which means two seats is booked, how can I validate the checkbox based on the number of seat(s) selected?
Here is my code:
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>";
}else{
echo "<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>";
}
}
?>
The full source code:
<?php include("header.php"); error_reporting(0); ?>
<?php
if(isset($_POST['submit'])){
$from = $_POST['from'];
$to = $_POST['to'];
$date = $_POST['d_date'];
$nop = $_POST['nop'];
$_SESSION['from'] = $from;
$_SESSION['to'] = $to;
$_SESSION['date'] = $date;
$_SESSION['nop'] = $nop;
$get = mysqli_query($mysqli,"SELECT * FROM routes WHERE present_loc = '$from' and destination = '$to' ");
while($roys = mysqli_fetch_array($get)){
//get bus details
$bno = $roys['bus_no'];
$ploc = $roys['present_loc'];
$des = $roys['destination'];
$time = $roys['dept_time'];
$_SESSION['time'] = $time;
$amt = $roys['amount'];
$_SESSION['amt'] = $amt;
$b = str_replace( ',', '',$_SESSION['amt'] );
if( is_numeric($b) ) {
$a = $b;
}
$bus = mysqli_query($mysqli,"select * from bus where bus_no = '$bno'");
while($bu = mysqli_fetch_array($bus)){
$_SESSION['model'] = $bu['model'];
$_SESSION['seat_no'] = $bu['seat_no'];
$_SESSION['ac'] = $bu['bus_type'];
$_SESSION['excess_luggage'] = $bu['excess_luggage'];
$_SESSION['more_legs'] = $bu['more_legs'];
$_SESSION['id'] = $bu['id'];
}
$coun = mysqli_query($mysqli, "select count(booking_id) as seat, seats from booking where bus_no = '$bno' and seats !='' GROUP by booking_id" );
$mseat = array();
while($e = mysqli_fetch_array($coun)){
$bseat = $e['seat'];
$mseat[] = $e['seats'];
}
//$seatss = array();
$seat_string = implode(",",$mseat);
//get seats
$couns = mysqli_query($mysqli, "select sum(counter) as seat from booking where bus_no = '$bno' and seats !='' GROUP by bus_no" );
$rseats = mysqli_fetch_array($couns);
$lseat = $rseats['seat'];
if($_SESSION['seat_no'] == $lseat){
$tell = " No more seat(s) available.";
}else{
$tell = $_SESSION['seat_no'] - $lseat. " Seat(s) remaining.";
}
}
}
?>
<!--Main layout-->
<main class="mt-5">
<!--Main container-->
<form action="details" method="POST">
<!--Grid row-->
<div class="row">
<div class="col-lg-12 title-header mb-3 mx-auto z-depth-1">
<div class="row">
<div class="col-lg-8">
<?php echo '<h2> '.$_SESSION['from']. ' to '. $_SESSION['to']. '</h2>'; ?><br/>
<b><?php echo $_SESSION['date']; ?> :: <?php if($_SESSION['nop'] < '2') { echo $_SESSION['nop'] . ' Adult'; }
elseif($_SESSION['nop'] > 1) { echo $_SESSION['nop'] . ' Adults'; }
?></b>
</div>
</div>
</div>
<div class="col-lg-12 mbody"> <label style="margin-left: 4%; font-weight:bolder; font-size:20px; color:#000;">Details </label> </div>
<div class="col-lg-12 mbody bg-white ">
<table class="table table_view" style = "width: 100%; margin-left: 4%; margin-right:4%;">
<tbody>
<tr>
<td><b><?php echo $_SESSION['model']; ?></b><br/><?php echo $_SESSION['from']. ' to '. $_SESSION['to']; ?>
<br/><?php if($_SESSION['ac'] == 'AC') { echo '<span class="alert-info ac">'. $_SESSION['ac'] .'</span>'; }
else{ echo '<span class="alert-warning">No AC</pan>'; } ?>
<?php if($_SESSION['more_legs'] == 'Yes') { echo '<span class="alert-info ac">More Leg Room</span>'; }
else{ echo '<span class="alert-warning no">More Leg Not Available</pan>'; } ?>
</td>
<td><b>Departing Time</b><br/><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo $_SESSION['time']; ?></td>
<td> <img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> <?php echo $tell; ?></td>
<td>Adult <b>₦<?php echo $_SESSION['amt']; ?></b></td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-12">
<div class="col-lg-12 mbody"> <label style="margin-left: 3%; font-weight:bolder; font-size:20px; color:#000;"><img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> Select Seat</label> </div>
<div class="row detail">
<!--Grid column-->
<div class="col-lg-7 animation slideUp" >
<div class="well" id="bus_seats_layout" >
<table class="table table-bordered" cellspacing = "1" id="seatstable">
<tr>
<td><img id = "driverimg" src="../images/seatsLayout/steering.png" class="img-responsive" width="25" height="25"></td>
<td colspan="2" rowspan="3">
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "
<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>
";
}else{
echo "
<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>
";
}
}
?>
</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-5">
<ul class="bt">
<li><img src="../images/seatsLayout/seat_available.png" class="img-responsive"> Available</li>
<li><img src="../images/seatsLayout/picked.png" class="img-responsive"> Selected</li>
<li><img src="../images/seatsLayout/seat_booked.png" class="img-responsive"> Booked</li>
</ul>
</div>
</div>
<div class="col-lg-12">
<input type="hidden" name="bus_no" value="<?php echo $bno; ?>">
<input type="hidden" name="to" value="<?php echo $to; ?>">
<input type="hidden" name="from" value="<?php echo $from; ?>">
<input type="hidden" name="amt" value="<?php echo $nop*$a; ?>">
<input type="hidden" name="nop" value="<?php echo $nop; ?>">
<div class="form-group">
<div align="right">
<input type="submit" name="submit" class="bme" value="Continue">
</div>
</div>
</div>
</div>
</div>
</form>
</main>
<?php include("footer.php"); ?>
I'm trying to create a search form in codeigniter. This is my controller and model,
Shop.php [ Controller ]
public function s(){
$q = $this->input->get('q');
if( $q == null ){
$this->index();
}
$data['products'] = $this->product_model->search_products( $q );
$this->load->view('shop', $data);
}
Product_model.php
public function search_products( $keyword ){
$this->db->select('product.id, product.product_name, product.product_description, product.product_image1,
brand.brand_name, category.category_name, type.type_name, stock.selling_price,
(SELECT COALESCE(ROUND(SUM(rate)/( COUNT(rate)*5 )*100), 0) FROM rating WHERE rating.product_id = product.id)AS rating,
(SELECT COALESCE(COUNT(rating.id), 0) FROM rating WHERE rating.product_id = product.id)AS rate_count');
$this->db->from('product');
$this->db->join('stock','stock.product_id = product.id');
$this->db->join('brand', 'brand.id = product.brand_id');
$this->db->join('category', 'category.id = product.category_id');
$this->db->join('type', 'type.id = product.type_id');
$this->db->join('color', 'color.id = product.color_id');
$this->db->where('MATCH(product.product_name) AGAINST("'.$keyword.'")');
$this->db->or_where('MATCH(brand.brand_name) AGAINST("'.$keyword.'")');
$this->db->or_where('MATCH(category.category_name) AGAINST("'.$keyword.'")');
$this->db->or_where('MATCH(type.type_name) AGAINST("'.$keyword.'")');
$this->db->where('stock.qty >', 0);
$this->db->group_by('product.id');
$query = $this->db->get();
return $query->result_array();
}
But return value in null. So I tried calling search_product( $keyword ) function in my view and it worked. but when I print $data['product'] variable and its empty.
What is the problem here? Thank you.
Edit
The search result shows here.
<div class="row product-list-item">
<?php
// This is just used for check the query
$p = $this->product_model->search_products( 'mesh' );
echo '<br>';
print_r($products);
if( $products != null ){
foreach ( $products as $product ){
?>
<!-- item.2 -->
<div class="product-item-element col-sm-6 col-md-6 col-lg-4">
<!--Product Item-->
<div class="product-item">
<div class="product-item-inner">
<div class="product-img-wrap">
<img src="<?php echo base_url($product['product_image1']);?>" alt="">
</div>
<div class="product-button">
<i class="fa fa-eye"></i>
</div>
</div>
<div class="product-detail">
<p class="product-title"><a href="<?php echo site_url('shop/view/'.$product['id'])?>">
<?php echo $product['product_name']; ?>
</a></p>
<div class="product-rating">
<div class="star-rating" itemprop="reviewRating" itemscope="" itemtype="" title="Rated 4 out of 5">
<span style="width: <?php echo $product['rating'];?>%"></span>
</div>
<a href="#" class="product-rating-count">
<span class="count"><?php echo $product['rate_count'];?></span> Reviews
</a>
</div>
<p class="product-description">
<?php echo $product['product_description']; ?>
</p>
<h5 class="item-price"><?php echo $product['selling_price']; ?></h5>
</div>
</div>
<!-- End Product Item-->
</div>
<?php
}
}else{
?>
<div class="text-center no-items">
<h4>No items</h4>
</div>
<?php } ?>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row text-center">
<?php
if($_GET[id] == 0)
{
$querysb = mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
}
else
{
$querysb = mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
}
while($rowsb = mysql_fetch_assoc($querysb))
{
if($val == '6' || $val =='10'){
$classname = 'whitebg';
} else {
$classname = 'bg-blue co-white';
}
?>
<div class="col-md-4 mrgnBtm15">
<div class="<?php echo $classname;?> padding30" style="min-height: 250px">
<h3 class="service-heading">
<?php echo $rowsb['cname'];?>
</h3>
<h4>
RS <?php echo $rowsb['price'];?><br>
</h4>
<div class="mrgnTop15 clearfix"></div>
<a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
<font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
I am working on a dynamic website. here is the code of a particular page. In this page there is a div section with class="col md-4". If the number of content panel in that division appears to 5 or 7 in that case I want only the last panel (i.e 5th and 7th) to be in full column (col-12). What should I do?
Since you are using col-md-4, 3 divs will be shown each row. So I think what you are looking for is a way to make the last div full width if its going to be alone in its row. In that case, you will need to make it col-md-12 on 4th (not 5th) and 7th and 10th records and so on. This is exactly what the following code does,
I think what you want to do is show the
<?php
if($_GET[id] == 0)
{
$querysb=mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
}
else
{
$querysb=mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
}
$number_of_records = mysql_num_rows($querysb);
$counter = 1;
while($rowsb=mysql_fetch_assoc($querysb))
{
if($val == '6' || $val =='10'){
$classname= 'whitebg';
}else{
$classname= 'bg-blue co-white';
}
//if($number_of_records %3 ==1 && $counter == $number_of_records)
if(($number_of_records == 5 || $number_of_records == 7) && $counter == $number_of_records)
$col_class = "col-md-12";
else
$col_class = "col-md-4";
?>
<div class="<?php echo $col_class;?> mrgnBtm15">
<div class="<?php echo $classname;?> padding30" style="min-height: 250px">
<h3 class="service-heading">
<?php echo $rowsb['cname'];?>
</h3>
<h4>
RS <?php echo $rowsb['price'];?><br>
</h4>
<div class="mrgnTop15 clearfix"></div>
<a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
<font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
</div>
</div>
<?php
$counter++;
} ?>
</div>
</div>
</div>
i'm trying to relay the id through this if statement to see if the file exits. If it does I want to use the id to grab that image from the corporation-logos/ folder. If not i'd like to simply show a default image. I can't tell if its catching the id or not as it keeps spitting out the default.
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$imgStock="http://www.stocksandstocks.com/corporation-logos/$id.jpg";
$http_image="http://www.stocksandstocks.com/images/no-logo-default.png";
if(file_exists($imgStock))
{
$imgPick = "$imgStock";
}
else
{
$imgPick = "$http_image";
}
echo "
<ul>
<li>
<div class='wrapPicks'>
<div class='symbolPicks'>
<div class='quoteTitle'>$quoteTitle</div>
</div>
<div class='bgPicks'>
<img src='$imgPick' height='50px' widht='80px' alt='stock symbol $quoteTitle logo' />
<div class='separateWrap'>
<div class='quote'>
<b>Entry Price:</b> $$entry
</div>
<div class='quote'>
<b>Last trade:</b> $$lastPrice
</div>
</div>
<div class='quoteReturn'>
<b>Open P/L:</b>
<div class='bigGreen'>
<span style=\"color: $color\">$positive $$profit </span>
</div>
</div>
</div>
</div>
</li>
</ul>";