I've been stuck for about a week now on trying to get some query results in my reply to comments module in codeigniter. I am most certainly able to insert the replies to comments and have them linked to the proper comment.
I am not able to return the results of the replies however. I have based my query structure on the comments results which I'm able to display.
Here is the code:
inserting the replies and trying to pull the results on the controller:
public function insert_airwaves_comments_replies($profile_id)
{
//echo $profile_id;
$this->load->model('account_model');
$this->load->library('session');
$this->load->helper('date');
$user = $this->account_model->user();
$session_id = $this->session->userdata['id'];
$data['user'] = $user;
$this->load->model('community_model');
$this->load->library('form_validation');
$submit = $this->input->post('sub_comment_reply');
$this->load->library('session');
$airwave = $this->community_model->get_airwave_comments($profile_id);
$data['airwave'] = $airwave;
if(isset($submit))
{
foreach($airwave as $airwave_id)
//if($this->form_validation->run() == FALSE)
// {
// $data['main_content'] = 'account/profile';
// $this->load->view('includes/templates/main_page_template', $data);
// }
// else
//{
$save_data = array(
'airwave_id' => $airwave_id['id'],
'from_id' => $session_id,
'comment' => $this->input->post('airwaves_comments_replies'),
'status' => 'active',
'datetime' => date('Y-m-d H:i:s',now())
);
$query = $this->community_model->save_airwaves_comments_replies($profile_id,$save_data);
$airwave_reply = $this->community_model->get_airwaves_comments_replies($profile_id);
$data['airwave_reply'] = $airwave_reply;
redirect('/account/profile/'.$profile_id);
}
//}
}
getting the results from the model:
public function get_airwaves_comments_replies($profile_id)
{
$session = $this->session->userdata('is_logged_in');
$user_id= $this->session->userdata('id');
if($profile_id == $user_id)
{
$comments_query = "SELECT
awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name
FROM
airwaves_comments_replies awr,
users u
WHERE
u.id=awr.from_id
AND awr.from_id =".$profile_id."
order by
awr.datetime
desc" ;
}
else
{
$comments_query = "SELECT awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name FROM airwaves_comments_replies awr,users u WHERE u.id = awr.from_id AND awr.from_id =".$profile_id." order by awr.datetime desc" ;
}
$query = $this->db->query($comments_query);
if($query->num_rows() >= 1)
{
$data = $query->result_array();
// return whole resultset. It contains zero, one or more records
return $data;
}
else return false;
}
displaying the results in my view:
if ($airwave_reply)
{
foreach ($airwave_reply as $airwave_reply_comment_row)
{ ?>
?>
<?php echo $airwave_reply_comment_row['from_id']; echo "<br />";
echo $airwave_reply_comment_row['first_name'];?>
<div class="response_structure_future">
<a name="response_<?php echo $airwave_reply_comment_row['id']; ?>"></a>
<div class="response_polaroid_future">
<a href="">
<img src='/styles/images/prof_thumbnail_2.jpg'/>
</a>
</div>
<div class="response_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="response_data_future">
<div class="response_name_future">
<a href="">
<?php echo $airwave_reply_comment_row['first_name'];?>says...
</a>
</div>
comment here
<div class="respond_info_future">
at <?php echo date('M d, Y',strtotime($airwave_reply_comment_row['datetime'])); ?>
<?php //if($auth->id == $replier->id || $auth->id == $result['ToUserID']) ?>
<a onclick="confirmation('');"> • delete</a>
<?php ?>
<div id="thumb_holder">
<div id="thumb_report">
<a href="mailto:info#cysticlife.org">
report
</a>
</div>
<div class= "thumb_counter" id="thumb_counter<?php// echo $reply['id']; ?>">
+<?php //echo $reply['thumbsUp_reply']; ?>
</div>
<div id="thumb_thumb">
<?php $comment_reply_id = $reply['id'];?>
<a class="myButtonLink" href="Profile.php?id=<?php //echo $prof->id; ?>" id="<?php //echo $comment_reply_id; ?>">Vote Up!</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<a name='reply_form_<?php echo $airwave_comment_row['id']; ?>' style="clear:both"></a>
<div id='reply_to_<?php echo $airwave_comment_row['id']; ?>' class="respond_structure_future" <?php if(isset($_GET['reply_to']) && $_GET['reply_to'] == $airwave_comment_row['id']) { echo 'style="display:block;"';}else{ echo 'style="display:none;"';} ?>>
<div class="response_polaroid_future">
<a href="http://www.cysticlife.org/Profile.php?id=<?php// echo $auth->id; ?>">
<img src="/styles/images/prof_thumbnail_2.jpg" />
</a>
</div>
<?php
echo validation_errors();
echo form_open('community/insert_airwaves_comments_replies/'.$this->uri->segment(3));
?>
<div class="respond_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="respond_data_future">
<?php
$data = array('name' => 'airwaves_comments_replies', 'id' => 'reply_to'. $airwave_comment_row['id'].'_textarea', 'class' => 'respond');
echo form_textarea($data, set_value('airwaves_comments_replies'));
$data = array('type' => 'hidden', 'name' => 'comment', 'value' => $airwave_comment_row['id']);
echo form_input($data);
?>
<div class="respond_nevermind">
nevermind
</div>
<?php
echo form_submit('sub_comment_reply', 'Reply');
?>
</div>
</div>
</form>
</div>
please let me know what else you may need to help and thanks in advance.
What is your result right now?
With the code you are showing, your controller inserts the comment replies in a foreach-loop but redirects the user to
redirect('/account/profile/'.$profile_id)
I don't see any code where you call the view to show the comments, so i think we can't help you any further without some more explanation and code.
Related
I have created a method in a model to call all events from a database with images - this worked fine I then wanted to find ones that match a postcode so created another function which is called when a search bar is filled in and submitted. This other function works and loads all info from database except the images even the one that is hardcoded in the index page - I can't work out what I have done wrong or why it won't work.
I have tested the code in phpMyAdmin and the function returns the image-path, the index page must be okay because it returns everything on the other function which leaves the controller but i can't see anything wrong there either.
The model function code:
function FindEventByPostcode($id){
$this->db->query("SELECT
concert.concert_id as concertId,
event_type.id as typeId,
concert.type_id as typeCId,
concert.concert_name as concertName,
concert.date as concertDate,
users.name as userName,
concert.date as date,
concert.post_code as post_code,
concert.info as info,
images.image_path as imagePath,
event_type.type as type
FROM concert
JOIN event_type
ON concert.type_id = event_type.id
JOIN users ON
users.id = concert.user_id
JOIN images ON concert.image_id = images.id
WHERE concert.post_code = :post_code
ORDER BY concert.date DESC"
);
$this->db->bind(':post_code', $id);
$results = $this->db->resultSet();
return $results;
}
The controller code:
$events = $this->eventModel->getEventTypes();
class Pages extends Controller {
public function __construct(){
$this->eventModel = $this->model('Event');
$this->userModel = $this->model('User');
$this->pageModel = $this->model('Page');
}
public function index(){
if(isLoggedIn()){
redirect('profiles');
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$postcode = ($_REQUEST['post_code']);
$event = $this->pageModel->FindEventByPostcode($postcode);
$data =[
'title' => 'Forthcoming Events',
'events' => $event
];
$this->view('pages/index', $data);
}else{
$data = [
'title' => 'Forthcoming Events',
'events' => $events
];
$this->view('pages/index', $data);
}
}
}
The Index Page:
<?php require_once APPROOT . '/views/inc/header.php' ?>
<div>
<p>Event Finder</p>
<form name="postcode" method="post"
action="<?php echo URLROOT; ? >/pages/index">
<input type="text" name='post_code'/>
<input type="submit" value="find event">
</form>
</div>
<div class="col-md-6">
<h1><?php echo $data['title'] ?></h1>
</div>
<img src="img/concertBanner.jpg" style="width:100%"/>
<?php foreach($data['events'] as $post) : ?>
<div class="card card-body mb-3">
<img class="card-img-top" src="img/<?php echo $post->userName; ?>/
<?php echo $post->imagePath; ?>"
style="width:50%; height:50%;" alt="Card image cap">
<div class="card-body">
<h4 class="card-title"><?php echo $post->concertName; ?></h4>
<p class="card-text"> Event Info: <?php echo $post->info ?></p>
<p class="card-text"><?php echo $post->type ?></p>
<p></p>
<div class="bg-light p-2 mb-3">
Organised by <?php echo $post->userName; ?>
on <?php echo $post->date; ?>
</div>
<p class="card-text"><?php echo $post->concertName; ?> in
<?php echo $post->post_code; ?> </p>
<a href="<?php echo URLROOT; ?>/pages/show/
<?php echo $post->concertId;?>" class="btn btn-dark">More</a>
</div>
</div>
No error messages just a broken image link instead of the image.
I have a problem with this GET.
I want to pass on three values (ygo, dane, 1) with a link to index, so that these values are entered in the respective WHERE.
But unfortunately there is no value on the page and I just don't know why.
IMG:
https://screenshots.firefox.com/g6qcToRn.../127.0.0.1
Controller:
public function index($slug) {
$url = 'edition/index';
$array = explode ('/',$url);
$data['array'] = $array[0];
$data['title'] = 'Edition Liste';
$data['edition_listes'] = $this->Edition_model->edition_listess($slug);
$this->load->view('templates/header', $data);
$this->load->view($url, $data);
$this->load->view('templates/footer');
}
public function edition($tcg,$id,$short) {
$url = 'edition/edition';
$array = explode ('/',$url);
$data['array'] = $array[0];
$data['get_edition'] = $this->Edition_model->get_edition($tcg,$id,$short);
$this->load->view('templates/header', $data);
$this->load->view($url, $data);
$this->load->view('templates/footer');
}
Model:
public function edition_listess($slug) {
$this->db->select('*');
$this->db->from('db_edition');
$this->db->where('db_edition.tb_edition_tcg', $slug);
$this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
$this->db->order_by('db_edition.tb_edition_date', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
public function get_edition($tcg,$id,$short) {
$this->db->select('*');
$this->db->from('db_edition');
$this->db->where('db_edition.tb_edition_tcg', $tcg);
$this->db->where('db_edition.tb_edition_id', $id);
$this->db->or_where('db_edition.tb_edition_kurzel', $short);
$this->db->order_by('db_edition.tb_edition_kurzel', 'ASC');
$this->db->order_by('db_edition.tb_edition_date', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
index.php
<?php echo validation_errors(); ?>
<title><?php echo $title; ?></title>
<div class="row">
<div class="col-xs-6 col-lg-1">
</div>
<div class="col-xs-6 col-lg-10">
<?php foreach ($edition_listes as $edition_liste): ?>
<div class="list-group">
<a href="<?php echo base_url(); ?>edition/edition/<?php echo $edition_liste['tb_edition_tcg'];?>/<?php if($edition_liste['tb_edition_kurzel'] > '') { echo $edition_liste['tb_edition_kurzel']; } else { echo $edition_liste['tb_edition_id']; } ?>" class="list-group-item list-group-item-action list-group-item-secondary">
<div class="media">
<img class="media-object img-rounded img-responsive" src="<?php echo base_url(); ?>/assets/images/display.png" alt="placehold.it/350x250">
<div class="media-body">
<h4 class="list-group-item-heading"><?php echo $edition_liste['tb_edition_name'];?></h4>
<p class="list-group-item-text">
<b>SET ID: </b><?php if($edition_liste['tb_edition_kurzel']): echo $edition_liste['tb_edition_kurzel']; endif; ?></br>
<b>Kartenmenge: </b><?php echo $edition_liste['tb_edition_size'];?></br>
<b>Release: </b>00.00.0000
</p>
</div>
<div class="col-md-3 text-right">
<h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-check-square"></i></button></h5>
<h5 class="colors">Pre-Release: <button class="btn btn-primary"><i class="fa fa-square"></i></button></h5>
</div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<div class="col-xs-6 col-lg-1">
</div>
</div>
edition.php (test page)
<?php echo validation_errors(); ?>
<?php echo $slug; ?>
It looks like you are not passing the third argument to edition($tcg,$id,$short). That likely means your model is using null for the value of $short in the call to $this->db->or_where('db_edition.tb_edition_kurzel', $short); so it is probably not returning any records.
Your code could be a lot easier to read. Here is code-snippet suggestion on how to create the link to the edition controller
...
<div class="list-group">
<?php
$tcg = $edition_liste['tb_edition_tcg'];
if($edition_liste['tb_edition_kurzel'] !== '') // use a more reliable test for an empty string than > ''
{
$id = $edition_liste['tb_edition_kurzel'];
}
else
{
$id = $edition_liste['tb_edition_id'];
}
$short = 1;
?>
<a href="<?= base_url("edition/edition/$tcg/$id/$short"); ?>" class="list-group-item list-group-item-action list-group-item-secondary">
...
In case you are not familiar with the syntax <?= is exactly the same as <?php echo - but with a lot less typing.
Now, a bonus suggestion. I'm not sure exactly why you are using this code
$url = 'edition/index';
There is a way to get the current controller and method without hard-coding it.
$url = $this->router->class . '/' . $this->router->method;
That way if you rename the controller or the method you don't have to change the hard-coded string. Yeah!
CodeIgniter does not document the router class, but the source code is in /system/core/Router.php and every controller will have an instance of the router class available as the property $this->router.
So I currently have three tables like this given below:
AI = auto increment.
ci_users: user_id(AI), username, slug, email, biography.
ci_terms: term_id(AI), title, slug, body.
ci_relationship: id(AI), term_id, user_id, type.
I'm trying to display all the users from a specific term_id(where type is skill),
for example, let's say term_id 3(where term_id has the title of 'CSS' from ci_terms).
To make it more clear,the above paragraph basically says show me all users with skill of CSS but I want the displayed users to show all of their other skills which are stored in the ci_relationship table.
PARAGRAPHS BELOW ARE AFTER CLICKING A SPECIFIC TERM_ID(SKILL).
This is the function which shows me all of the users that have the term_id as their skill.(from my previous Stackoverflow question. Thanks to pradeep who helped me solve that query:
// All users with specific skill
public function get_user_skill($id)
{
$this->db->select('*, count(ci_relationship.term_id)');
$this->db->from($this->table);
$this->db->join('ci_relationship', 'ci_relationship.user_id = ci_users.id', 'INNER');
$this->db->order_by('ci_relationship.user_id', 'DESC');
$this->db->group_by('ci_relationship.user_id');
$this->db->where('ci_relationship.term_id', $id);
$this->db->where('ci_relationship.type', 'skill');
$query = $this->db->get();
if($query->num_rows() > 0)
{
return $query->result();
}
else
{
return false;
}
}
As I said before the code above just display the users with the specific term_id. Now this is the method in the controller which shows the expected data(users with specific term_id):
This is my controller :
public function skill($id){
// Get data
$data['users'] = $this->User_model->get_user_skill($id);
$term = $this->Terms_model->get($id);
// Get skill name
$data['skill'] = $this->Terms_model->get($id);
// Get skills per foreach --- HERE IS WHERE I NEED HELP
$data['skills'] = $this->User_model->skills($id);
// Meta
$data['title'] = $this->settings->title.' | '. ucfirst($term->title);
// Load template
$this->template->load('public', 'default', 'users/skill', $data);
}
This is the method that I'm trying to create to displayed the term_id per user_id:
// Skill for user foreach
public function skills($id){
$this->db->select('*');
$this->db->from($this->relationship);
$this->db->where('term_id', $id);
$this->db->where('type', 'skill');
$this->db->order_by('id', 'DESC');
$query = $this->db->get();
if($query->num_rows() >= 1){
return $query->result();
} else {
return false;
}
}
The view is the following code:
<?php if($users) : ?>
<div class="row">
<?php foreach($users as $user) : ?>
<div class="col-lg-3 col-sm-6">
<div class="card text-center panel">
<div class="cardheader panel-heading" style="background: url(<?php if($user->user_id) : echo base_url('assets/img/users/covers/'.get_username($user->user_id).'/'.get_username_cover($user->user_id)); else : echo base_url().'assets/img/noavatar.jpg'; endif ?>)no-repeat center center;"></div>
<div class="avatar">
<a target="_self" href="<?= base_url('users/profile/'.get_username($user->user_id)); ?>"><img class="img-circle" alt="<?= get_username($user->user_id); ?> profile picture" title="<?= get_username($user->user_id); ?> profile picture" src="<?php if($user->user_id) : echo base_url('assets/img/users/avatars/'.get_username($user->user_id).'/'.get_username_avatar($user->user_id)); else : echo base_url().'assets/img/noavatar.jpg'; endif ?>"></a>
</div>
<div class="info panel-body">
<div class="title">
<a target="_self" href="<?= base_url('users/profile/'.get_username($user->user_id)); ?>"><?= get_username($user->user_id); ?></a>
</div>
<div class="desc"><?php if(get_occupation($user->user_id)) : ?><?= get_occupation($user->user_id); ?><?php else : echo 'No Job'; endif ?> <?php if(get_company($user->user_id)) : ?> - <b><?= get_company($user->user_id); ?></b><?php else : echo '- <b>No Company</b>'; endif ?></div>
<!-- BEGINNING OF HERE IS WHERE I NEED HELP -->
<?php if($skills) : ?>
<?php foreach($skills as $skill) : ?>
<span class="label label-orange"><?= get_term($skill->term_id) ?></span>
<?php endforeach ?>
<?php endif ?>
<!-- END OF HERE IS WHERE I NEED HELP -->
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<div class="alert alert-danger">No user with <?= $skill->title ?> skill found</div>
<?php endif; ?>
This is the actual output:
And this is the expected output:
I hope I could explain myself well enough to make it easy to understand,thanks in advance.
Hope this will help you :
Create a helper method get_skill_by_user just like get_username or get_occupation and use it in your view
function get_skill_by_user($user_id, $id)
{
$ci = & get_instance();
$ci->db->select('*');
$ci->db->from('ci_relationship');
$ci->db->where('term_id', $id);
$ci->db->where('user_id', $user_id);
$ci->db->where('type', 'skill');
$ci->db->order_by('id', 'DESC');
$query = $ci->db->get();
if($query->num_rows() > 0)
{
return $query->result();
} else
{
return false;
}
}
In your view your skills loop should be like this :
<?php $user_skills = get_skill_by_user($user->user_id, $user->term_id); if($user_skills) : ?>
<?php foreach($user_skills as $skill) : ?>
<span class="label label-orange"><?= get_term($skill->term_id) ?></span>
<?php endforeach ?>
<?php endif ?>
Normally when I get the data from my database I there are arranged in the order of their id.However, I have created a column called 'sales' which is also an integer
and I would like my data to be arranged in ascending order according to the sales.Here is my code:
My Model
public function get_bestseller($id = FALSE) {
if ($id === FALSE)
{
$query = $this->db->get('submit');
return $query->result_array();
}
$query = $this->db->get_where('submit', array('id' => $id));
$this->db->order_by('sales', 'DESC');
return $query->result_array();
}
My View
<div class="tab-pane fade" id="faq-cat-2">
<div class="panel-group" id="accordion-cat-2">
<?php foreach ($bestseller as $bestseller_item): ?>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img class="lazy" src="<?php echo base_url() ?>Images/last.gif"
data-original="<?php echo base_url() ?>uploads/<?php echo $bestseller_item['imgname']; ?>"
style="width: 350px; height: 150px">
<div class="caption">
<?php if ($bestseller_item['Price'] == 0): ?>
<h4 class="pull-right"><p class="text-success">Free</p></h4>
<?php else: ?>
<h4 class="pull-right">$<?php echo $bestseller_item['Price']; ?></h4>
<?php endif; ?>
<h4>
<a href="<?php echo site_url('submit/view/' . $bestseller_item['id']); ?>"
target="_blank"><?php echo $bestseller_item['Title']; ?></a>
</h4>
<p><?php echo $bestseller_item['textarea']; ?></p>
</div>
<p class="text-right"><b
class="author">By: <?php echo $bestseller_item['Author']; ?></b>
</p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
My Controller
public function index()
{
$data['bestseller'] = $this->Submit_Database->get_bestseller();
$this->load->view('templates/header');
$this->load->view('pages/home', $data);
$this->load->view('templates/footer');
}
$query = $this->db->order_by('sales', 'DESC')->get_where('submit', array('id' => $id));
You are adding the order by clause after the query has already ran.
How to do pagination in Yii without any grid view and listview
I was stack in their for two days
these is my controller
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$pages = new CPagination(OfferEvents::model()->count());
$pages ->pageSize = 2;
$pages -> applyLimit($criteria);
$post= OfferEvents::model()->findAll($criteria);
$this -> render('index', array('post' => $post, 'pages' => $pages));
}
and my view
<?php foreach($models as $model): ?>
<?php for($x = 0; $x < $arrlength; $x++) { ?>
<?php if($catiddet == 1){?>
<div class="col-sm-4">
<div class="list-box fadeInDown ">
<div class="img-box-1">
<img src="<?php echo $offerListArray[$x]['offerimg']; ?>" style="width:360px;height:202px;" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Event</a>
</div>
<div class="text-box">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<div class="round-box clear"><span><h1><?php echo $diff ?><small>Days</small></h1></span></div>
<p style="height:19px;overflow: hidden;"> <b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div>
</div>
</div>
<?php } else{?>
<div class="col-sm-4" >
<div class="list-box">
<div class="img-box-1">
<?php $filepathnw=$offerListArray[$x]['offerimg'];
//if (file_exists($filepathnw)) { $filepathSrc=Yii::app()->baseUrl.'/'.$filepathnw; } else
//{ $filepathSrc='http://www.childnet.com/pimages/1351720/thumbnail4.jpg'; }
?>
<img src="<?php echo $filepathnw; ?>" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Offer</a>
</div>
<div class="text-box" style="padding:2px !important;">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<span><h1><?php echo $diff ?><small>Days</small></h1></span>
<span><h1><?php echo $offerListArray[$x]['discountper']; ?>%<small>DISCOUNT</small></h1></span>
<span><h1>$<?php echo $offerListArray[$x]['discountperamt']; ?><small>You Save</small></h1></span>
<div class="text-box" style="padding:15px;">
<p style="height:19px;overflow: hidden;">
<b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div> </div>
</div>
</div>
<?php } ?>
<?php } ?>
<?php endforeach; ?>
// display pagination
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?>
out put comes fine..but the data repeats...
select * FROM offer_events WHERE enddate >= '$now' AND (title like '%$locationdet%' OR description like '%$locationdet%') AND type = '$catiddet' ORDER BY id DESC LIMIT 6 ");
$datalat = $dbCommand->queryAll(); $numlatData=count($datalat);
// echo "<pre>"; print_r($datalat); echo "</pre>";
$latlongdats='';
if($numlatData!=0){
foreach($datalat as $expertn)
{
$ids=$expertn['id'];
$offertitle=$expertn['title'];
if($expertn['image']!=""){ $imgUrl=$expertn['image']; } else { $imgUrl='image-not-available.png'; }
$infowinimgpath='theme/images/OfferEvents/thumb/'.$imgUrl;
if (file_exists($infowinimgpath)) { $infowinimgpathSrc=Yii::app()->baseUrl.'/'.$infowinimgpath; } else
{ $infowinimgpathSrc=Yii::app()->baseUrl.'/theme/images/OfferEvents/thumb/image-not-available.png'; }
$offerimg=$infowinimgpathSrc;
$latinow=$expertn['latitude'];
$longinow=$expertn['longitude'];
$latlongdats.="['".$ids."', ".$latinow.",".$longinow.",'".$offertitle."','".$offerimg."','".$expertn['startdate']."'],";
$offertList = array(
"id" => $ids,
"offertitle"=> $offertitle,
"offerimg" => $offerimg,
"description" => $expertn['description'],
"startdate" => $expertn['startdate'],
"enddate" => $expertn['enddate'],
"discountper" => $expertn['discountper'],
"discountperamt" => $expertn['discountperamt']
);
array_push($offerListArray,$offertList);
}
$zoomlevel=3;
$latlongdatsfinal=rtrim($latlongdats, ",");
} else { $latlongdatsfinal="['','',''],"; $ErrorMsgmap="No Result Found."; }
}
and could you please explain me how this happend???
You can use CActiveDataProvider to perform your pagination needs
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$post= new CActiveDataProvider('OfferEvents', array(
'criteria' => $criteria,
'pagination'=>array('pageSize' => 2),
));
$this -> render('index', array('post' => $post));
}
In your view, instead of using foreach loop, use ListView / GridView and pass the CActiveDataProvider instance ($post) in your case
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$post,
'itemView'=>'_post', // refers to the partial view named '_post'
));
the "_post.php" subview file would contain
$data->property // whatever properties you have set for 'OfferEvents'