I have the following code which displays a theatre show feed on my website, coming from an external ticketing company.
<!-- PULL IN SHOW FEED -->
<div class="container">
<div class="col-md-12 whats-on-feed">
<!-- PULL IN SHOW FEED -->
<div class="container">
<div class="col-md-12 whats-on-feed">
<?php
$xml = simplexml_load_file('https://tickets.leicesterymca.co.uk/feed/shows');
if(isset($wp_query->query_vars['month'])) {
$month = $wp_query->query_vars['month'];
$fromDate = date("Y"). '-'. $month;
$shows = $xml->xpath("//*[contains(ActiveFrom,'$fromDate')]");
}else if(isset($wp_query->query_vars['genre'])) {
$genre = str_replace("-", " ", $wp_query->query_vars['genre']);
if($genre != 'all'){
$shows = $xml->xpath("//*[Genres/Genre/#Name='$genre']");
}else{
$shows = $xml;
}
}else{
$shows = $xml;
}
?>
<div class="block-grid-xs-1 block-grid-sm-2 block-grid-md-3 block-grid-lg-4 show-list">
<?php
$i = 1;
foreach ($shows as $Show) {
$activeFrom=date_create($Show->ActiveFrom);
$activeTo=date_create($Show->ActiveTo);
if(strlen($Show->ShowId) > 0){
?>
<div>
<div class="box">
<div class="caption">
<h3><?php echo $Show->Name ?></h3>
<p><?php echo $activeFrom->format('D d M Y'); ?></p>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<a href='/show?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>More Info</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<a href='/buy?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>Buy Tickets</a>
</div>
</div>
</div>
<div class='image-holder' style='background-image: url("<?php echo $Show->SmallImageUrl ?>");' /></div>
</div>
</div>
<?php $i++; }} ?>
</div>
</div>
This is coming from an XML feed that the ticketing company outputs from their system.
Currently they are displaying in order of show ID, I think this is the default, but I need them to display in order of date - The data node in the xml feed for date is: ActiveFrom.
I have seen this solution:
<xsl:sort select="ActiveFrom" order="ascending" />
But I don't really know if A: it's the correct approach, or B: Where I would add it in relation to my code? Can anyone help?
You can try this code
$xml = 'https://tickets.leicesterymca.co.uk/feed/shows';
$data = simplexml_load_file($xml);
$encode = json_encode($data);
$decode = json_decode($encode, true);
$show = $decode['Show'];
//function to sort by array value
function date_compare($a, $b) {
$t1 = strtotime($a['ActiveFrom']);
$t2 = strtotime($b['ActiveFrom']);
return $t1 - $t2;
}
usort($show, 'date_compare');
//test active from value
foreach ($show as $time) {
echo $time['ActiveFrom'].'<br>';
}
//echo '<pre>'.print_r($show, true).'</pre>';
Edited
<?php
$xml = 'https://tickets.leicesterymca.co.uk/feed/shows';
$data = simplexml_load_file($xml);
$encode = json_encode($data);
$decode = json_decode($encode);
$results = $decode->Show;
//function to sort by object (not array)
function date_compare($a, $b) {
$t1 = strtotime($a->ActiveFrom);
$t2 = strtotime($b->ActiveFrom);
return $t2 - $t1; // reverse it to check it works or not $t2 - t1
}
usort($results , 'date_compare');
if(isset($wp_query->query_vars['month'])) {
$month = $wp_query->query_vars['month'];
$fromDate = date("Y"). '-'. $month;
$shows = $xml->xpath("//*[contains(ActiveFrom,'$fromDate')]");
}
else if(isset($wp_query->query_vars['genre'])) {
$genre = str_replace("-", " ", $wp_query->query_vars['genre']);
if($genre != 'all'){
$shows = $xml->xpath("//*[Genres/Genre/#Name='$genre']");
}else{
$shows = $results;
}
}
else {
$shows = $results;
}
?>
<!--next-->
<?php
$i = 1;
foreach ($results as $Show) {
$activeFrom = date_create($Show->ActiveFrom);
$activeTo = date_create($Show->ActiveTo);
if(strlen($Show->ShowId) > 0){
?>
<div>
<div class="box">
<div class="caption">
<h3><?php echo $Show->Name ?></h3>
<p><?php echo $activeFrom->format('D d M Y'); ?></p>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<a href='/show?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>More Info</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<a href='/buy?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>Buy Tickets</a>
</div>
</div>
</div>
<div class='image-holder' style='background-image: url("<?php echo $Show->SmallImageUrl ?>");' /></div>
</div>
</div>
<?php $i++; }} ?>
</div>
</div>
Related
So i want to place this code below
$keyword="";
if (isset($_POST['searchpakaian'])) {
$keyword = $_POST['searchpakaian'];
}
$query = mysqli_query($conn,"SELECT * FROM tbl_pakaian WHERE nama_pakaian LIKE '%".$keyword."%' ORDER BY id ASC limit 0,6");
$hitung_data = mysqli_num_rows($query);
if ($hitung_data > 0) {
while ($row = mysqli_fetch_array($query)) {
?>
<div class="col">
<div class="card h-100">
<div class="card-img-wrap ">
<img src="img/Galeri/pakaian/<?php echo $row['gambar_pakaian'] ?>" class="card-img-top" alt="...">
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $row['nama_pakaian'] ?></h5>
<p class="card-text "><?php echo $row['keterangan_pakaian'] ?></p>
</div>
</div>
</div>
<?php } } else { ?>
<center><h4>Tidak Ada Data</h4></center>
<?php } ?>
On if conditional statement
if($req == 'something'){
}
Here is my full code
<?php
include '../koneksi.php';
$req = $_REQUEST['req'];
$keyword="";
if (isset($_POST['searchpakaian'])) {
$keyword = $_POST['searchpakaian'];
}
$query = mysqli_query($conn,"SELECT * FROM tbl_pakaian WHERE nama_pakaian LIKE '%".$keyword."%' ORDER BY id ASC limit 0,6");
$hitung_data = mysqli_num_rows($query);
if ($hitung_data > 0) {
while ($row = mysqli_fetch_array($query)) {
?>
<div class="col">
<div class="card h-100">
<div class="card-img-wrap ">
<img src="img/Galeri/pakaian/<?php echo $row['gambar_pakaian'] ?>" class="card-img-top" alt="...">
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $row['nama_pakaian'] ?></h5>
<p class="card-text "><?php echo $row['keterangan_pakaian'] ?></p>
</div>
</div>
</div>
<?php } } else { ?>
<center><h4>Tidak Ada Data</h4></center>
<?php } ?>
If i just copy the code to the if conditional statement code, it just say 'unexpected end of file'
What should i do?
The syntax error are vey simple to find just confirm that when you copy inside the if, dont repeat php keys as and the echo finish it with ;
<?php echo('hello world'); ?>
OR the same echo but simple deleting the php tag by = simbol (only work with echo)
<?= 'hello world' ?>
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>
this is a text file content which will be chatting database
you:2016-05-02 11:41:53 Hi
Muhammad:2016-05-02 11:42:41 Hi
you:2016-05-02 11:43:33 How are you ?
Muhammad:2016-05-02 14:44:56 I'm fine!
this is the code to loop to get content
<?php
$chat = file("members/cdn/1/chats/9188.txt");
foreach($chat as $line){
$name = strchr($line,":",true);
$message = explode(' ', substr(strchr($line,":"),1), 3);
if(some thing){
?>
<div>
<!-- here i want to skip the same dates -->
<?=$message[0];?>
</div>
<?php
}
?>
<div class="container">
<div class="arrow">
<div class="outer"></div>
<div class="inner"></div>
</div>
<div class="message-body">
<p><?=$message[2];?></p>
<p class="message_time"><?=date("g:i a", strtotime($message[1]));?></p>
</div>
</div>
<div class="spacer"></div>
<?php
}
?>
I want the date of the message appear one time above of messages in the same date
Simply remember that date you last used and then compare it to the one in $message[0]
<?php
$lastDate = NULL;
$chat = file("members/cdn/1/chats/9188.txt");
foreach($chat as $line) :
$name = strchr($line,":",true);
$message = explode(' ', substr(strchr($line,":"),1), 3);
if($lastDate != $message[0]) :
$lastDate = $message[0];
?>
<div><?=$message[0];?></div>
<?php
endif;
?>
<div class="container">
<div class="arrow">
<div class="outer"></div>
<div class="inner"></div>
</div>
<div class="message-body">
<p><?=$message[2];?></p>
<p class="message_time"><?=date("g:i a", strtotime($message[1]));?></p>
</div>
</div>
<div class="spacer"></div>
<?php
endforeach;
?>
Try this:
$prevDate[] = array();
foreach($chat as $line){
$name = strchr($line,":",true);
$message = explode(' ', substr(strchr($line,":"),1), 3);
if(some thing){
?>
<div>
<!-- here i want to skip the same dates -->
<?php
if(!in_array($message[0],$prevDate)) { // check if date exist in array - means displayed previously or not
echo $message[0];
$prevDate = $message[0]; // store date in array so that next time you can check whether it has been already displayed or not
}
?>
</div>
<?php
}
?>
<div class="container">
<div class="arrow">
<div class="outer"></div>
<div class="inner"></div>
</div>
<div class="message-body">
<p><?=$message[2];?></p>
<p class="message_time"><?=date("g:i a", strtotime($message[1]));?></p>
</div>
</div>
<div class="spacer"></div>
<?php
}
First, you can use list assignment to get the components split out into separate vars:
list($user,$date,$time,$message) = explode(' ', substr(strchr($line,":"),1), 4);
Then you can use a simple comparison to see if the date is new:
if ($date != $last_date) {
$last_date = $date;
?><div><?=$date?></div><?php
}
You should declare $last_date before the loop, but you can leave its value undefined.
So this is the function from model Publicationdata that sends the result array to controller based on the author id that controller provides it->
public function getSpPubData($tId)
{
$this->db->order_by("pub_year", "desc");
$q = $this->db->get_where('rsc_faculty_publications', array('pub_author_id' => $tId));
$error = $q->num_rows() > 0 ? FALSE : TRUE;
if ($error === FALSE)
{
return $q->result();
}
else{
return $error;
}
}
now on controller i am saving the array as-
$data['pubData'] = $this->Publicationdata->getSpPubData("10006);
the rsc_faulty_publications table has a field pub_year.. now on view when I am accessing $pubData on view.. i want to print the publications yearwise. they will be printed in a loop when the current year publications will be at top.. so what I want is to fetch the yearwise publications from $pubData through loop.. the view is like this-
<?php
for($i=0;$i<sizeof($pubData);$i++){ ?>
<div class="panel panel-info">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion<?php echo $pubData[$i]->pub_year; ?>" href="#year<?php echo $pubData[$i]->pub_year; ?>" title="Click to expand/collapse">
<h4 class="panel-title">Publication Year: <?php echo $pubData[$i]->pub_year; if($pubData[$i]->pub_year==date('Y')){echo " (".sizeof($pubData)." Publications until now)";}?></h4>
</div>
<div id="year<?php echo $pubData[$i]->pub_year; ?>" class="panel-collapse collapse">
<div class="panel-body">
<?php while($pubData[$i]->pub_year==$pubData[$i+1]->pub_year){
?>
<div class="well well-info">
<p><?php echo $pubData[$i]->pub_title; ?></p>
<p><?php echo $pubData[$i]->pub_authors; ?></p>
<p><?php echo $pubData[$i]->pub_publisher; ?></p>
</div>
<?php
}?>
</div>
</div>
</div>
<?php } ?>
First load the view file in controller and pass the data.
$this->load->view('view_file', $data);
Use following code in the view file to retrieve the data.
foreach($pubData->brands as $brand): ?>
after getting the value from model say
$data['value']=$this->model1->getValue();
Now you can pass the value you obtained to view page like this
$this->load->view('viewpagename',$data);
Now in the view page you can easily access it using the array name you passed .ie value. So in the view page do
foreach($value as $val){
print what you want here
}
<?php $i=0;
$n=0;
$brands = array('info','warning','primary','success');
$len=sizeof($pubData);
while($i<$len){ ?>
<?php if($i==0||$i-1!==-1 && $pubData[$i]->pub_year!==$pubData[$i-1]->pub_year){ ?>
<div class="panel panel-<?php echo $brands[$n];?>">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion1" href="#year<?php echo $pubData[$i]->pub_year; ?>" title="Click to expand/collapse">
<h4 class="panel-title">Publication Year: <?php echo $pubData[$i]->pub_year; if($pubData[$i]->pub_year==date('Y')){echo " (".sizeof($pubData)." Publications until now)";}?></h4>
</div>
<div id="year<?php echo $pubData[$i]->pub_year; ?>" class="panel-collapse collapse">
<div class="panel-body">
<?php
}?>
<div class="well well-<?php echo $brands[$n];?>">
<p><?php echo $pubData[$i]->pub_title; ?></p>
<p><?php echo $pubData[$i]->pub_authors; ?></p>
<p><?php echo $pubData[$i]->pub_publisher; ?></p>
</div>
<?php if($i==$len-1 || $i+1!==$len && $pubData[$i]->pub_year!==$pubData[$i+1]->pub_year){
if($n==3){$n=0;}else{$n++;} ?>
</div>
</div>
</div >
<?php } $i++;
} ?>
I'm making a site with conrete5. It's the first one I might add. I have made myself a couple of custom blocks. Named News, Teammates and References.
Now News and Teammates are not editable anymore. I will paste the News -blocks sourcecode.
----------- FORM.php ---------------------
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('optional', 'fID', t('Valitse kuva'), $bf, $args);
?>
<div class="form-group">
<?php echo $form->label('otsikko', t('Otsikko'));?>
<?php echo $form->text('otsikko', $otsikko);?>
</div>
<div class="form-group">
<?php echo $form->label('teksti', t('Teksti'));?>
<?php echo $form->text('teksti', $teksti); ?>
</div>
<div class="form-group">
<?php echo $form->label('korkeus', t('Korkeus'));?>
<?php echo $form->select('korkeus', array("108px"=>t("Pieni"),"299px"=>t("Iso")), $korkeus); ?>
</div>
<div class="form-group">
<?php echo $form->label('koko', t('Leveys'));?>
<?php echo $form->select('koko', array("col-md-3"=>t("Pieni"),"col-md-6"=>t("Iso")), $koko); ?>
</div>
<div class="form-group">
<?php echo $form->label('link', t('Linkki'));?>
<?php echo $form->text('link', $link); ?>
</div>
<div class="form-group">
<?php $psh = Loader::helper('form/page_selector');
echo $psh->selectPage('targetCID', $targetCID); ?>
</div>
----------- view.php ---------------------
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$c = Page::getCurrentPage();
if($size=="col-md-3"){
$class='col-md-3';
$tag = $class;
}else{
$class="col-md-6";
$tag= $class;
}
if ($c->isEditMode()){
$class="editmode";
$editingStyle="padding: 15px; background: #ccc; color: #444; border: 1px solid #999;";
}
else {
$editingStyle = "";
}
$random = rand();
if($korkeus == "299px"){
$padding = '4px';
}else {
$padding = '5px';
}
$p = Page::getByID($targetCID);
$a = new GlobalArea('Header Navigation');
$blocks = $a->getAreaBlocksArray($c);
foreach ($blocks as $block){
if ($block->getBlockTypeHandle()=="autonav"){
$block->setCustomTemplate('cdrop.php'); // it's templates/cdrop.php -check the select option values when you set custom template manually at edit mode. I think you will need just "my_template"
$bv = new BlockView($block);
$bv->render('view');
}
}
?>
<?php $p = Page::getByID($targetCID); ?>
<a href="index.php">
<div class="pull-left <?= $koko;?>" style="padding:<?= $padding ?>;<?php echo $editingStyle;?>">
<div class="col-lg-12 alapalkki box" style="z-index:2;position:relative;">
<div class="image-big" style="background-color:transparent;text-align:center;position:relative;z-index:1;">
<!-- FiGuRe this shit out......... !-->
<?php
if($fID != 0){
$file = File::getByID($fID);
$filePath = $file->getVersion()->getRelativePath();
}
?>
<?php echo '<img src="' . $filePath . '" style="max-height:' . $korkeus . ';width:100%;"/>'; ?>
</div>
<div class="col-lg-12 " style="position:relative;z-index:255;padding:2px 0 0 15px;">
<div class="htitle">
<h4 style="color:white;"><b><?php echo $otsikko; ?></b></h4>
<p style="color:white;"><?php echo $teksti; ?></p>
</div>
</div>
</div>
</div>
</a>
Why is this not being an editable block? Why doesn't the concrete5 even recognize its existence when it is on the page? It just says at the area that it's empty.
$p = Page::getByID($targetCID);
$a = new GlobalArea('Header Navigation');
$blocks = $a->getAreaBlocksArray($c);
foreach ($blocks as $block){
if ($block->getBlockTypeHandle()=="autonav"){
$block->setCustomTemplate('cdrop.php'); // it's templates/cdrop.php -check the select option values when you set custom template manually at edit mode. I think you will need just "my_template"
$bv = new BlockView($block);
$bv->render('view');
}
}
?>
There's the problem. No idea what so ever what that is doing there..... Removed it. Worked like a charm.
-Kevin