VueJS #click not working in a foreach loop - php

I'm using VueJS CDN in my PHP project.
I created a loop (foreach) which fetches records and displays them in a table. I would like to load up a modal when I click on a button inside the table but it's not working or giving me any error as to why it isn't working.
Taking the button outside the table/loop works fine and accesses the VueJS method.
var app_admin = new Vue({
el: '#orders',
data: {
},
mounted: function(){
},
methods: {
getOrderDetails( order_id, order_no ){
alert( order_id +' | '+ order_no );
},
}
});
<div class="page-content-inner is-webapp" id="orders" v-cloak>
<?php
$get_orders = $db_con->prepare("SELECT oid, order_no, rider, created_at, status FROM ". ODS ." ORDER BY created_at DESC");
$get_orders->execute();
if ( $get_orders->rowCount() > 0 ){
?>
<div class="table-wrapper" data-simplebar>
<table id="empty-datatable" class="table is-datatable is-hoverable table-is-bordered">
<thead>
<tr>
<th>Order_No</th>
</tr>
</thead>
<tbody>
<?php
$rows = $get_orders->fetchAll();
foreach ( $rows as $row ){
?>
<tr>
<td>
<?php
if ( $row['status'] == 'Waiting' ){
?>
<button #click="getOrderDetails('show', <?=$row['oid'].', '.$row['order_no']; ?>)">Click</button>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div id="paging-first-datatable" class="pagination datatable-pagination">
<div class="datatable-info">
<span></span>
</div>
</div>
<?php
} else {
?>
<div class="col-12">
<div class="message is-primary">
<a class="delete"></a>
<div class="message-body">No Record Found!</div>
</div>
</div>
<?php
}
?>
<!-- PANEL -->
<?php
//include 'panels/Orders.All.OrderDetails.Panel.php'; // Order Details
?>
<!--// PANEL -->
</div>
The button doesn't access the getOrderDetails function while in the loop but taking it out works. What could I be doing wrong?

Related

PHP Output (PDO & CRUD)

I need help with my PHP script.
I have 3 Tables in my Database (its German so sorry if you dont understand ^^):
-firma (in english company)
-produkt (in english product)
-firmaprodukt (in english companyproduct)
If I click on a company, the product image should be output (from the "Produkt" database) and the appropriate URL (from the "firmaprodukt").
So far I've managed that when you click on a company, the ID is displayed (example: "localhost/TESTING//index?1=") but I'm struggling with the output.
That's my index.php script for the output:
<div class="col-xl-6">
<div id="login_content">
<div class="scrollP">
<?php
$fpresults = $fpCrud->getPicUrl($FirmenID);
?>
<div class="col-12 d-flex justify-content-center heading-div">
<h3> <?= $result['firmenname']?> </h3>
</div>
<table border="0">
<tbody>
<?php
foreach ($fpresults as $fpresult){
?>
<tr>
<div class="box customer-box" data-parent="#login_card" id="project_reg_box">
<img src="dashboard/TESTING/<?= $fpresult['ProduktLogo']?>" height="100%" >
</div>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
And that's in my crud.php:
public function getPicUrl($FirmenID) {
$stmt = $this->conn->query(
"SELECT fp.FirmenID, f.firmenname, p.ProduktLogo, fp.url
FROM firma f
JOIN firmaprodukt fp ON fp.FirmenID = f.FirmenID
JOIN produkt p ON fp.ProduktID = p.ProduktID
WHERE fp.FirmenID = :FirmenID");
$stmt->execute(array(':FirmenID' => $FirmenID));
$data = $stmt->fetch();
return $data;
}
In my formprocess.php I don't have anything for that.
My solution:
index.php
<?php
if (isset($_GET['firmaprodukte'])) {
$FirmenID = (int) $_GET['firmaprodukte'];
$firmaprodukte = $fpCrud->getPicUrl($_GET['firmaprodukte']);
$firmenresults = $firmaCrud->getFirma($_GET['firmaprodukte']);
?>
<div class="col-xl-6">
<div class="scrollP">
<div id="login_content">
<div id="login_card" class="container">
<?php
$fpresults = $fpCrud->getPicUrl($FirmenID);
?>
<div class="col-12 d-flex justify-content-center heading-div">
<h3> <?= $firmenresults['firmenname']?> </h3>
</div>
<table border="0">
<tbody>
<?php
foreach ($fpresults as $fpresult){
?>
<tr>
<div class="box customer-box" data-parent="#login_card" id="project_reg_box">
<img src="dashboard/TESTING/<?= $fpresult['ProduktLogo']?>" height="80vh" max-width="200vh">
</div>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
Crud.php
public function getPicUrl($FirmenID) {
$stmt = $this->conn->prepare("SELECT fp.FirmenID, f.firmenname, p.ProduktLogo, fp.url FROM firma f JOIN firmaprodukt fp ON fp.FirmenID = f.FirmenID JOIN produkt p ON fp.ProduktID = p.ProduktID WHERE fp.FirmenID = :FirmenID");
$stmt->execute(array(':FirmenID' => $FirmenID));
$data = $stmt->fetchAll();
return $data;
}
formprocess.php
if(isset($_POST['firmaprodukte'])) {
$FirmenID = $_POST['FirmenID'];
if($crud->getPicUrl($FirmenID)) {
header('location: FirmaProdukt.php');
exit;
} else{
header('location: FirmaProdukt.php');
exit;
}
}

CodeIgniter | Sometimes the user session destroyed when adding cart item

Hi im working on my workshop tools project.
Now i have some strange action sometimes when i pressed the add to cart button (mine was named pinjam) it just going back to the login page because the session destroyed. Anyone has this strange thing happened? or Can you help me?
The scenario is like this..
I pressed the add to cart button on one of much tools that can i borrow, then it post to the add_to_cart function on my controller and reload the #cart_content div on that page with new added data with jquery / ajax
Controller Siswa
function index(){
$data['guru'] = $this->model_akun->getnamaguru();
$data['data']=$this->model_alat->getAll();
$this->load->view('siswa/dashboard',$data);
}
function add_to_cart(){
if($this->model_alat->validate_add_cart_item() == TRUE){
// Check if user has javascript enabled
if($this->input->post('ajax') != '1'){
redirect('siswa'); // If javascript is not enabled, reload the page with new data
}else{
echo 'true'; // If javascript is enabled, return true, so the cart gets updated
}
}
}function show_cart(){
$this->load->view('siswa/cart');
}
Model_Alat
function validate_add_cart_item(){
$id = $this->input->post('id_alat'); // Assign posted id_alat to $id
$cty = $this->input->post('quantity'); // Assign posted quantity to $cty
//$this->db->where('id_alat', $id); // Select where id matches the posted id
$query = $this->db->query('select * from alat where id_alat="'.$id.'"')->result(); // Select the products where a match is found and limit the query by 1
//$ss = $this->input->post('ajax');
//echo $query['id_alat'];
//echo "<script>alert(".$cty.");
// </script>";
// Check if a row has been found
if($query > 0){
foreach ($query as $row){
$data = array(
'id' => $id,
'qty' => $cty,
'price' => '0',
'name' => $row->nama_alat
);
$this->cart->insert($data);
return TRUE;
}
// Nothing found! Return FALSE!
}else{
echo "<script>alert('FALSE no rows :(');</script>";
return FALSE;
}
}
JQUERY
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
siswa/cart (for viewing the cart list)
##siswa/cart view
<div class="table-responsive">
<?php echo form_open('siswa/update_cart'); ?>
<table class="table table-bordered">
<thead >
<tr>
<th>Alat</th>
<th>Jumlah</th>
<!--<th>Total</th>-->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $a=0; $b=0;foreach($this->cart->contents() as $items): ?>
<tr>
<!--<input type="hidden" id="id_peminjam" name="id_peminjam" value="'.$this->session->userdata('ses_id').'"/>-->
<td><?php echo form_hidden('rowid['.$a.']', $items['rowid']);
echo $items['name']; ?></td>
<td><?php echo form_input(array('name' => 'qty['.$a.']', 'value' => $items['qty'], 'maxlength' => '2'), '', 'class="form-control form-control-sm"'); ?></td>
<!--<td><button type="button" id="'.$items['rowid'].'" class="romove_cart btn btn-danger btn-sm">Cancel</button></td>-->
<td><?php echo form_submit('', 'Update', 'class="btn btn-accept btn-sm"');
$b=$a+1;?>
</tr>
<?php $a++; endforeach; ?>
</tbody>
</table>
<?php echo form_hidden('jumlah_alat', $b);
echo form_close();?>
<?php echo form_open('siswa/sub_cart'); ?>
<table class="table">
<tr>
<td >
<select name="id_guru" class="form-control form-control-sm">
<option>Pilih Guru</option>
<?php foreach($guru as $gurus): echo '<option value='.$gurus->id_akun.'>'. $gurus->nama .'</option>'; endforeach;?>
</select>
</td>
<td>
<?php $hitung=0; $b=0; foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden('id_alat'.$hitung.'', $items['id']);
echo form_hidden('jumlah_pinjam'.$hitung.'', $items['qty']);
echo form_hidden('id_siswa', $this->session->userdata('ses_id'));
$b=$hitung+1;
$hitung++;
endforeach;
echo form_hidden('jumlah_alat', $b);
echo anchor('siswa/empty_cart', 'Hapus Semua', 'class="btn btn-danger btn-sm col-sm-5"'); ?>
<?php echo form_submit('', 'Pinjam!', 'class="btn btn-primary btn-sm col-sm-5"');?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
</div>
FORM siswa/dashboard
<!DOCTYPE html>
<head>
<?php $this->load->view("admin/_partials/head.php") ?>
</head>
<body id="page-top">
<!-- Navbar-->
<?php $this->load->view("siswa/_partials/navbar.php") ?>
<div id="wrapper">
<!-- Sidebar-->
<?php $this->load->view("siswa/_partials/sidebar.php") ?>
<div id="content-wrapper">
<div class="container-fluid">
<div class="row ">
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">Alat Tersedia</h4>
<br>
<div class="row card-body">
<?php foreach ($data as $row) : ?>
<div class="col-md-6">
<div class="card mb-3">
<div class="card-header text-center"><?php echo $row->nama_alat;?>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-7">
Tersedia
</div>
<div class="col-md-5">
<input value="<?php echo $row->jumlah;?>" class="form-control form-control-sm" readonly>
</div>
</div>
<div class="subalat">
<?php echo form_open(''); ?>
<div class="row">
<div class="col-md-7">
Mau Brp?
</div>
<div class="col-md-5">
<?php echo form_hidden('id_alat', $row->id_alat);
echo form_input('quantity', '1', 'maxlength="2" class="form-control form-control-sm"'); ?>
</div>
</div>
<br>
<?php echo form_submit('add', 'Pinjam','class="btn btn-success btn-block col-md"'); ?>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
<?php endforeach;?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">List Pinjam</h4>
<!--<div class="card-body">-->
<div id="cart_content">
<?php $this->load->view('siswa/cart'); ?>
</div>
<!--</div>-->
<div class="card-footer small text-muted">
Jika jumlah alat nya 0(nol), alat akan dihapus. Page rendered in <strong>{elapsed_time}</strong> seconds.
</div>
</div>
</div>
</div><!-- /.row -->
</div><!-- /.content-fluid -->
<!-- Sticky Footer -->
<?php $this->load->view("siswa/_partials/footer.php") ?>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<?php $this->load->view("siswa/_partials/scrolltop.php") ?>
<!-- Modal-->
<?php $this->load->view("siswa/_partials/modal.php") ?>
<!-- Js-->
<?php $this->load->view("siswa/_partials/js.php") ?>
</body>
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
</script>
</html>
Login controller
class Login extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model("model_login");
}
function index(){
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if($this->form_validation->run()==FALSE){
$session = $this->session->userdata('isLoggedin');
if($session == FALSE){
$this->load->view('login');
}
else{
redirect('');
}
}
else{
$email=$this->input->post('email');
$password=$this->input->post('password');
$cek_akun=$this->model_login->auth_akun($email,$password);
if($cek_akun->num_rows() > 0){
$user_data=$cek_akun->row_array();
$this->session->set_userdata('isLoggedin',TRUE);
$this->session->set_userdata('ses_id',$user_data['id_akun']);
$this->session->set_userdata('ses_nama',$user_data['nama']);
if($user_data['level']=='admin'){ //level admin
$this->session->set_userdata('level','admin');
redirect('admin');
}
else if($user_data['level']=='aspiran'){ //level aspiran
$this->session->set_userdata('level','aspiran');
redirect('aspiran');
}
else if($user_data['level']=='guru'){ //level guru
$this->session->set_userdata('level','guru');
redirect('guru');
}
else if($user_data['level']=='siswa'){ //level siswa
$this->session->set_userdata('level','siswa');
redirect('siswa');
}
}
else{
$this->load->view('login');
echo "<script>alert('Failed Login: Check your username and password!');
</script>";
}
}
}
function logout(){
$this->session->sess_destroy();
$url=base_url('');
redirect($url);}}

Ajax Pagination backward move in cakephp 3

I am doing ajax pagination in cakephp 3.2
I have done code for forward move of pagination, by getting the last id .
If i want to go backward ,the pagination will not work ,i know .
How can i do it in a proper way so that it will work for both direction as well as direct click on any pagination index.
Below i have attached some of my codes ,which is working properly only for forward move of pagination.
I know the code won't work for backward move.
How can i do it?
///////////////////////////////////PAGINATION STARTS HERE/////////////////////////////////////////////////
if(isset($_POST["page"])){
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //filter number
if(!is_numeric($page_number)){die('Invalid page number!');} //incase of invalid page number
}else{
$page_number = 1; //if there's no page number, set it to 1
}
$item_per_page=5;
$get_total_rows = $this->Orders->find('all')->where($condition)->count(); //hold total records in variable
$total_pages = ceil($get_total_rows/$item_per_page);
$page_position = (($page_number-1) * $item_per_page);
if($page_number>1)
{
$condition[] = ['Orders.id >' => $_POST["lastId"]];
}//this one fetch all list greater than last id
$Lists = $this->Orders->find('all')->where($condition)->order(['Orders.id' => 'ASC'])->limit($item_per_page)->toArray();
Thank you
Your Controller Action code should be
$this->paginate = [
'order'=>[
'field_name'=>'desc'
]
];
$condition = [];
$query = $this->YourModel->find()->where($conditions);
$this->set('records', $this->paginate($query));
In view your code should be for listing part only, I dont know whta is your HTML structure but you can follow this, and dont forget about id=pagination_list_container in parent of your table and pagination link code.
<div class="panel-body" id="pagination_list_container">
<div class="inner-spacer">
<table class="table table-striped table-hover margin-0px">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('field_1', 'Column 1') ?></th>
<th><?php echo $this->Paginator->sort('field_2', 'Column_2') ?></th>
<th><?php echo $this->Paginator->sort('field_3', 'Column_3') ?></th>
</tr>
</thead>
<tbody>
<?php
if (empty($records->toArray())) {
?>
<tr><td colspan="100%" class="text-danger text-center">No record found</td></tr>
<?php
} else {
foreach ($records as $record):
?>
<tr>
<td><?php echo $record->field_1 ?></td>
<td><?php echo $record->field_2; ?></td>
<td><?php echo $record->field_3; ?></td>
</tr>
<?php endforeach; ?>
<?php } ?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-6">
<ul class="pagination">
<?php
$this->Paginator->templates([
'current' => '<li class="active"><a>{{text}}</a></li>',
'number' => '<li>{{text}}</li>'
]);
echo $this->Paginator->prev('«');
echo $this->Paginator->numbers();
echo $this->Paginator->next('»');
?>
</ul>
</div>
<div class="col-md-6 text-right">
<div class="mt30">
<?php
echo $this->Paginator->counter(
'Page {{page}} of {{pages}}, showing {{start}} to {{end}} of {{count}}'
);
?>
</div>
</div>
</div>
</div>
Make AJAX behaviour in your view
You have to Apply Some Javascript event for ajax behaviour into #pagination_list_container
$(document).ready(function(){
$("document").on('click','#pagination_list_container .pagination li a, #pagination_list_container table th > a', function(e){
e.preventDefault();
var link= $(this).attr('href');
if(link!="")
{
$("#pagination_list_container").load(link+ "#pagination_list_container", function(){
console.log("data loaded");
})
}
return false;
});
});

How to create table in foreach

This is my php code
<?php
include_once 'conectDB.php';
$sql ='SELECT CHECKLISTS.USER_ID, CHECKLISTS.ADMIN_ID, PROGRAMS.PROGRAM_NAME
FROM CHECKLISTS
LEFT JOIN COMPUTERS
ON CHECKLISTS.USER_ID = COMPUTERS.COMPUTER_NAME
LEFT JOIN ADMINS
ON CHECKLISTS.ADMIN_ID = ADMINS.USER_ID
LEFT JOIN CHECKLIST_PROGRAMS
ON CHECKLISTS.ID = CHECKLIST_PROGRAMS.CHECKLIST_ID
LEFT JOIN PROGRAMS
ON PROGRAMS.ID = CHECKLIST_PROGRAMS.PROGRAM_ID
';
$result = $connection->query($sql);
$checklists = array();
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
$checklists [] = $row;
}
} else {
echo '0 results';
}
$connection->close();
?>
And this is HTML CODE
in this foreach I don't know how to query and create table :(
<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<title>C.I.G. Check List</title></head>
<body>
<div class="container">
<div class="row" style="margin-top:10px;">
<div class="col-md-offset-2 col-md-8">
<div class="row" style="margin-top:20px;">
<div class="col-md-4"><h3>C.I.Gruop Checklist</h3></div>
<div class="col-md-6" style="margin-top:19px; font-size:20px;">New Item</div>
</div></div>
</div>
<div class="col-md-2"></div>
<div class="row" style="margin-top:20px;">
<div class="col-md-offset-1 col-md-9">
<!-- ส่วนแสดงผล -->
<?php
foreach ($checklists as $checklist) {
print_r($checklist);
}
?>
</div>
</div>
</div
</body>
</html>
You need to do like this:-
<table>
<?php
foreach ($checklists as $checklist) {
echo '<tr><td>'.$checklist.'</td></tr>';
}
?>
</table>
Creating table in foreach is simple. Try this:
<table>
<thead>
<tr>
<th>Check List</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checklists as $checklist) {
?>
<tr>
<?php
echo "<td>" . $checklist . "</td>";
?>
</tr>
<?php
}
?>
</tbody>
</table>
One option can be:
<table>
<? foreach ($checklists as $checklist) { ?>
<tr>
<td>
<? echo $checklist; ?>
</td>
</tr>
<? } ?>
</table>
Within the loop, everything you write is repeated as many times as the checklist items

Editing a php scripèt divs to output a table

Hey guys ok so i'm wokring on a clients Weekly Newsletter i'm working with Joomla 2.5.19 and using the enterprise version of acymailling to send it out. I'm kicking my heading in at the moment because of outlook, i'm using a module from Jreviews that publishes the latest reviews submitted to the site in the newsletter, it all works fine except in outlook.
the out put of the script is meant to be a 2x2table with the 4 latest reviews in it. the only prob is outlook seems to hates me using Div for a table and stacks the 2x2 table into a verticle kaotic mess.
the code i'm trying to edit is:
'>
<?php /* root element for the items */ ?>
<div class="jrModuleItems <?php echo $orientation . ' jrThumbnail'.ucfirst($tn_position); ?>">
<?php /* new page starts here */
$pages = array_chunk($reviews,$limit);
$j=0;
foreach($pages AS $page):
?>
<div class="jr-results jrResults jrModuleContainer jrReviewsModule">
<?php $i=0;
while(!empty($page)):
$i++; $j++; $review = array_shift($page); ?>
<?php
// Process link title
$listing_title = ($listing_title_chars && mb_strlen($review['Listing']['title'])>$listing_title_chars) ? $Text->truncate($review['Listing']['title'],$listing_title_chars) : $review['Listing']['title'];
$review_title = ($review_title_chars && mb_strlen($review['Review']['title'])>$review_title_chars) ? $Text->truncate($review['Review']['title'],$review_title_chars) : $review['Review']['title'];
$link_title = str_replace('{listing_title}',$listing_title,$link_title_format);
$link_title = str_replace('{review_title}',$review_title,$link_title);
// Create the thumbnail
$tn_show and $mainMediaThumb = $Media->thumb(Sanitize::getVar($review,'MainMedia'),array('listing'=>$review,'size'=>$tn_size,'mode'=>$tn_mode,'css_size'=>true));
?>
<?php $lastItem = ($i == $columns) ? ' jrLastItem' : ''; ?>
<div class="jrModuleItem<?php echo $lastItem; ?>" style="width: <?php echo $item_width; ?>%; padding-right: <?php echo $item_padding; ?>%;">
<?php if($show_numbers):?><div class="jrModuleItemNumber"><?php echo $j;?>.</div><?php endif;?>
<?php if($tn_show && $mainMediaThumb && $tn_position != 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
<div class="jrModuleItemContent">
<!-- Listing Title -->
<div class="jrModuleItemTitle">
<?php echo $Html->sefLink($link_title,$review['Listing']['url']);?>
<?php if(Sanitize::getString($review['Listing'],'tag')):?>
<span class="jrComponentLabel jrStatusLabel jrBlue">
<?php echo Sanitize::getString($review['Listing'],'tag');?>
</span>
<?php endif;?>
</div>
<!-- Rating -->
<?php if ( $review['Criteria']['state'] == 1 ):?>
<div class="jrOverallRatings">
<?php if($review['Review']['editor'] == 1):?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'editor');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallEditor" title="<?php __t("Editor rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php else:?>
<?php
$rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'user');
$rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
?>
<div class="jrOverallUser" title="<?php __t("User rating"); ?>">
<div class="jrRatingStars"><?php echo $rating_stars ?></div>
<span class="jrRatingValue"><?php echo $rating_value?></span>
</div>
<?php endif;?>
</div>
<?php endif;?>
<!-- Reviewer name -->
<div class="jrModuleItemReviewer">
<span class="reviewer"><?php __t("Reviewed by");?> <?php echo $Community->screenName($review);?></span>
</div>
<?php if($fields): ?>
<!-- Custom Fields -->
<div class="jrModuleFields">
<?php
foreach ($fields as $field):
$field = trim($field);
$field_value = $CustomFields->field($field,$review);
?>
<?php if($field_value != ''):?>
<div class="jrModuleFieldDiv <?php echo lcfirst(Inflector::camelize($field)); ?>">
<span class="jrModuleFieldTitle"><?php echo $CustomFields->label($field, $review); ?>: </span>
<span class="jrModuleFieldValue"><?php echo $field_value; ?></span>
</div>
<?php endif;?>
<?php endforeach; ?>
</div>
<?php endif;?>
<?php if($show_comments && trim($review['Review']['comments'])!=''):?>
<!-- Review Comments -->
<div class="jrModuleItemInfo">
<?php
// Uncomment line below to show review title
// echo '<strong>' . $review['Review']['title'] . '</strong><br />';
?>
<span class="comments">"<?php echo $Text->truncateWords($review['Review']['comments'],$comments_words,'...');?>"</span>
</div>
<?php endif;?>
</div>
<?php if($tn_show && $mainMediaThumb && $tn_position == 'bottom'):?>
<!-- Listing Thumbnail -->
<div class="jrModuleItemThumbnail">
<?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
<?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
// echo $Community->avatar($review);
?>
</div>
<?php endif;?>
</div>
<?php /*end of row , start new row*/
if(!empty($page) && ($i == $columns || $total == $j)):?>
<div class="jrDivider"></div>
<?php $i=0; endif;?>
<?php endwhile;?>
</div>
<?php endforeach; /* new page ends here */?>
</div><?php /* end items root element */?>
Does any one have the slightest idea how i could turn this into a for loop that outputs a table?
The quickest path from A to B is to edit the attached code to render a table versus stacked divs.
* EDIT *
The answer to your comment isn't so simple as replace all of 'A' with 'B.' A div is a "self-contained" HTML element while a table is a grouping with syntax rules.
An HTML table is constructed like so:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 - Column 1</td>
<td>Row 1 - Column 2</td>
</tr>
<tr>
<td>Row 2 - Column 1</td>
<td>Row 2 - Column 2</td>
</tr>
</tbody>
</table>
The foreach loop in your code should create a row through each iteration. Which means you need to render your table, thead and tbody tags outside of this looping code. Inside the loop, you render a new row each iteration, which requires an opening/closing tag for the row and an opening/closing for each column.
Hope this helps.

Categories