I want to echo a div only once in a Clistview, the items are order by status, so, i want to print status 1 -> all the items, and then status 2 -> all the items with that status, I tried viewData, but I dont know how to change the value of the flag.
INDEX VIEW:
<div class="modal-body">
<?php
$activos_flag = 1;
$inactivos_flag = 1;
?>
<?php
$this->widget('zii.widgets.grid.CListView', array(
'id'=>'incs',
'summaryText'=>'',
'dataProvider'=>$dataProviderInc,
'itemView'=>'_incidencias',
'viewData'=> array('activo'=> $activos_flag,'inactivo'=>$inactivos_flag),
));
?>
</div>
_INCIDENCIAS VIEW:
<?php
if ($data->activo == 1 and $data->incidencia_estado == 1){
echo ('<label class="incidencias">ACTIVOS</label>');
$data->activo = 0;
}
if ($data->inactivo == 1 and $data->incidencia_estado == 0){
echo ('<label class="incidencias">INACTIVOS</label>');
$data->inactivo = 0;
}
?>
You need to get the value not from the array $data ($data->inactivo) but directly from a variable $inactivo. But in any case, at each iteration, the value of these variables will again be equal to 1. In this case, you can use the following approach:
Before widget declaration:
Yii::app()->params['activos_flag']=1;
Yii::app()->params['inactivos_flag']=1;
and in parial view:
if ( Yii::app()->params['activos_flag'] == 1 ){
echo ('<label class="incidencias">ACTIVOS</label>');
Yii::app()->params['activos_flag'] = 0;
}
if ( Yii::app()->params['inactivos_flag'] == 1 ){
echo ('<label class="incidencias">INACTIVOS</label>');
Yii::app()->params['inactivos_flag'] = 0;
}
Related
I'm trying to get the data from two tables after an "Open" button is clicked from previous table UI by sending an Id.
e.g.
<a name="Open" href="<?php echo base_url('welcome/WellProfile/'.$post->Id) ?>">
(https://imgur.com/6IU1Tfo)
So I have two tables - namely "WellDataA" and "WellDataB" , I want to get the data where WellDataB data matches with the WellDataA by WellName(column).
Example:
WellDataA:
Id Platform WellName
.
.
4 ZE ZE-A
5 ZE ZE-B
6 ZE Ze-B
.
.
WellDataB:
Id WellName CompleteDate
1 ZE-A 12/3
2 ZE-B 14/5
3 ZE-C 20/6
This is how my query so far, but it ended up error
public function get_news_by_id($Id = 0)
{
if ($Id === 0)
{
$query = $this->db->get('WellDataA');
return $query->result_array();
}
$this->db->select('*');
$this->db->from('WellDataA');
$this->db->join('WellDataB','WellDataA.WellName =
WellDataB.WellName','INNER');
$query = $this->db->get_where('WellDataA', array('Id' => $Id));
return $query->row_array();
}
I expect the output would show ZE, ZE-A, 12/3 when "Open" button is clicked on ZE-A. But the actual output is ZE, ZE-A only. Thank you so much in advance!:)
Try this, your issue is in get_where() so, i removed it and rewrite it
public function get_news_by_id($Id = 0)
{
if ($Id === 0)
{
$query = $this->db->get('WellDataA');
return $query->result_array();
}
$this->db->select('a.Id,a.Platform,a.WellName,b.Id,b.CompleteDate');
$this->db->from('WellDataA a');
$this->db->join('WellDataB b','a.WellName = b.WellName','INNER'); //changes
$this->db->where('b.Id',$Id); //changes
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->row_array();
}else{
return array();
}
}
Firstful I am sorry if my solution won't be a good one,
but I suggest you change the structure of your tables to this:
WellDataA:
Id Platform WellDataB
.
.
4 ZE 1
5 ZE 2
6 ZE 3
.
.
WellDataB:
Id WellName CompleteDate
1 ZE-A 12/3
2 ZE-B 14/5
3 ZE-C 20/6
Since I assume that the used model is relational, one thing must first achieved is to make the tables all relational. Instead of connecting WellDataA and WellDataB with the Id from WellDataB inside WellDataA.
I think you just need to remove some code. Just try this code
public function get_news_by_id($Id = 0)
{
if ($Id === 0)
{
$query = $this->db->get('WellDataA');
return $query->result_array();
}
$this->db->join('WellDataB','WellDataA.WellName =
WellDataB.WellName','INNER');
$query = $this->db->get_where('WellDataA', array('Id' => $Id));
return $query->row_array();
}
I hope some kind person can help me out here.
I want to sort nested comments in wordpress by likes. I have only found one plugin that does this and it doesn't meet my needs, so I'm attempting to write my own. Most of it is actually pretty straightforward, but the sql is eluding me (not really my strength).
I need an SQL Query to sort comments by likes, with replies immediately following their parent, and replies to each parent also sorted by likes. Top level comments and replies are differentiated by 'layer'. There is only one level of replies. My table looks like this:
ID (Int)
Comment_Name (VarChar)
Layer (Int)... 1 for top level comment, 2 for reply
ID_of_Parent_Comment (Int)... replys must be grouped under top level comment with this id
Likes (Int)
For example, if top level comments are represented by numbers and replies by letters, it would look something like this:
1, 2, 3, 3a, 3b, 4, 5, 5a... etc
Anyone have any ideas?
It turns out that the other answer did not quite work out after all. It sure looked right. Replies were grouped nicely beneath the appropriate parent comment, everthing was sorted by likes. But if you look closely, the sqlfiddle test returned 14 records where there are only 12 available.
After spending way too much time fiddling with it on my site, I couldn't resolve it any further. One group or the other (top level comments or replies) were always either left off or duplicated.
I finally gave up, assuming that it could not be done with SQL, so I went back to something I was familiar with: php. Here is my solution. Hopefully someone will find it useful. If nothing else, it was a fun project.
myComments.php
<?php
global $wpdb;
$post_ID = get_the_ID();
// Get Comment Table
$sql =
" SELECT *"
." FROM wp_comments"
." WHERE comment_post_ID = " . $post_ID // only retrieve comments for this post
." AND comment_parent = '0'" // only retrieve top level comments
." ORDER BY likes DESC"
.";";
$tlc = $wpdb->get_results($sql, ARRAY_A); // Retrieve all records into $tlc
// this should never be
// large enough to be a problem.
$commentCount = count( $tlc ); // Number of TopLevelComments
// Adjust Comments
for ( $i = 0; $i <= $commentCount-1; $i++ ) {
$tlc[$i]['layer'] = 0; // Layer 0 indicates top level comment
$tlc[$i]['index'] = $i; // index is used to group parents
// with children
}
// Get Reply Table
$sql =
" SELECT *"
." FROM wp_comments"
." WHERE comment_post_ID = " . $post_ID
." AND comment_parent > '0'" // only retrieve replies
." ORDER BY likes DESC"
.";";
$replies = $wpdb->get_results($sql, ARRAY_A);
$replyCount = count( $replies );
// Adjust Replies
for ( $i = 0; $i <= $commentCount-1; $i++ ) {
$replies[$i]['layer'] = 1; // Layer 1 indicates replies
}
// Set child index to that of parent
// then add child record to parent array
for ( $i = 0; $i <= $replyCount-1; $i++ ) {
$x = $replies[$i]['comment_parent']; // Get ID of parent
for ( $j = 0; $j <= $commentCount-1; $j++ ) {
if ( $tlc[$j]['comment_ID'] == $x ) { // If parent found
$value = $tlc[$j]['index']; // Get parent's index
$replies[$i]['index'] = $value; // Give child parent's index
array_push ( $tlc, $replies[$i]);
}
}
}
// Sort comments
// Note that $tlc was sorted by select
// and index was assigned while in that order
$tlc = array_orderby($tlc, 'index', SORT_ASC,
'layer', SORT_ASC,
'likes', SORT_DESC);
// Display comments
$commentCount = count($tlc);
if ( $commentCount ) {
echo "<ol class='commentNumbering'>";
// Used to determine if we have opened a second <ol> for nested comments
// and ensure we close it before we are done.
$inReplyList = false;
// We don't want to close the <ol> before we've opened it.
$firstComment = true;
for ( $i = 0; $i <= $commentCount-1; $i++ ) {
$myComment = $tlc[$i];
// Set $depth (needed by reply-link on myCommentTemplate page)
$depth = 0;
$comment_ID = $myComment['comment_ID'];
while( $comment_ID > 0 ) {
$tempComment = get_comment( $comment_ID );
$comment_ID = $tempComment->comment_parent;
$depth++;
}
// Treat each group of nested comments as a separate ordered group
if ( $depth == 2 ) {
if ( ! $inReplyList ) {
echo "<ol>";
$inReplyList = true;
}
} else {
if ( ! $firstComment ) {
if ( $inReplyList ) {
echo "</ol>";
$inReplyList = false;
}
}
}
$firstComment = false;
// Display each comment
include ('myCommentTemplate.php');
}
if ( $inReplyList ) {
echo "</ol>";
}
echo "</ol>";
} else {
echo 'No comments found.';
}
// Where comments are made
include('myCommentForm.php');
$wpdb->flush();
?>
function array_orderby() (located in functions.php)
/* SORT PHP ARRAYS OF RECORDS */
// PHP function 'array_multisort' requires columns //
// This function handles the conversion from row to col and back again //
// Example:
// $sorted = array_orderby($data, 'volume', SORT_DESC, 'edition', SORT_ASC);
function array_orderby()
{
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array();
foreach ($data as $key => $row)
$tmp[$key] = $row[$field];
$args[$n] = $tmp;
}
}
$args[] = &$data;
call_user_func_array('array_multisort', $args);
return array_pop($args);
}
Looks like this should be close:
select
post.ID,
post.likes as postLikes,
reply.ID,
reply.likes as replyLikes
from MyTable post
left join MyTable reply
on post.ID = reply.ID_of_Parent_Comment
where post.ID_of_Parent_Comment is null
order by post.likes desc, reply.likes desc
;
It will give you the parent ID's sorted by parent likes and the related child ID's for each parent (if any) sorted by most liked child
As our products always have a minimum quantity I have used the file quantity-input.php to set this. This works fine for single products but when a variable product is selected the input field resets the min value to 1 and empties the max value. How do I set a min and max value on variable products as well?
In quantity-input.php
// Volume varaibles
$v1 = get_field('v1') ?: '1';
<div class="quantity buttons_added">
<?php echo $qty_start; ?><input id="inputNumber" type="number" step="<?php echo esc_attr( $step ); ?>" min="<?php echo $v1; ?>" max="9999" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" pattern="<?php echo isset( $pattern ) ? esc_attr( $pattern ) : ''; ?>" inputmode="<?php echo isset( $inputmode ) ? esc_attr( $inputmode ) : ''; ?>" /><?php echo $qty_end; ?>
</div>
The file is located in the global folder of woocommerce.
you should have not edited that file...
these hooks can achieve it. Just paste it in your theme's functions.php
add_filter( 'woocommerce_quantity_input_max', 'woocommerce_quantity_input_max' );
function woocommerce_quantity_input_max( $max ){
$max = 10;
return $max;
}
add_filter( 'woocommerce_quantity_input_min', 'woocommerce_quantity_input_min', 10, 2 );
function woocommerce_quantity_input_min( $min, $product ){
if ( $product->get_id() == 89 ) {
$min = 2;
} else {
$min = 3;
}
return $min;
}
you can even do some conditional statements on it.
Below is my code:
<?php
$url = $_GET['url'];
$wordlist = array("Www.", "Http://", "Http://www.");
foreach ($wordlist as &$word) {
$word = '/\b' . preg_quote($word, '/') . '\b/';
}
$url = preg_replace($wordlist, '', $url);
?>
<?php
$oDB = new PDO('mysql:dbname=mcnsaoia_onsafe;host=localhost;charset=utf8', 'mcnsaoia_xx', 'PASSWORD');
$hStmt=$oDB->prepare("SELECT * FROM users WHERE hjemmside = :hjemmside AND godkendt=ja");
$hStmt->execute(array('hjemmside' => $url));
if( $row = $hStmt->fetch() ){
echo "EXIST";
}else{
echo "NOT EXIST";
}
?>
My problem is that it says NOT EXIST, because I know that there is a row which should be found with the following query:
SELECT * FROM users WHERE hjemmside = :hjemmside AND godkendt=ja
So why does it say not exist? I have absolutely no idea :(
Instead of
$hStmt=$oDB->prepare("SELECT * FROM users WHERE hjemmside = :hjemmside
AND godkendt=ja");
try
$hStmt=$oDB->prepare("SELECT * FROM users WHERE hjemmside = :hjemmside
AND godkendt='ja'");
The left is most likely a column and the right side is a string? I don't speak your language, but this is the first thing coming to my mind.
You should surround with quotes your not integer variable in your query
AND godkendt='ja'
Or maybe let pdo deal with it
$hStmt=$oDB->prepare("SELECT * FROM users WHERE hjemmside = :hjemmside AND godkendt = :ja");
$hStmt->execute(array(':hjemmside' => $url, ':ja' => 'ja'));
//^ i added : for placeholder here, you missed it
I would also rather check if rows are returned
if($hStmt->$eowVount() > 0){
$row = $hStmt->fetch()
echo "EXIST";
}else{
echo "NOT EXIST";
}
Update (that one works)
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if ($node->type == 'webform') {
$count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d', $nid));
$atelier_1 = "sources" ;
$sql = "SELECT count(*) FROM {webform_submitted_data} WHERE data LIKE \"".$atelier_1."\" ;";
$count_atel_1 = db_result(db_query($sql));
}
}
echo $sql;
echo $count_atel_1;
?>
This webform has been submitted <?php print $count ?> times.
We'd like to use a webform so that our students should register on some workshops.
The webform works great. Now we'd like to display live the number of students that are already register in on of the workshops so that the other should know if there remains some possibilities of registration (each workshop can only accept 20 students at the same time)
I'm trying with that that doesn't work ($atelier_1 = "sources" ;) is the name of one workshop :
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
if ($node->type == 'webform') {
$count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d', $nid));
$atelier_1 = "sources" ;
$count_atel_1 = db_result(db_query('SELECT count(*) FROM {webform_submitted_data} WHERE data LIKE %d', $atelier_1');
}
}
echo $count_atel_1;
?>
Any help or suggestion welcome
The only way you can show that live, is by creating an ajax in drupal, or with drupal behaviours, or with javascript.