Posts Tagged with select

Displaying 11-20 of 24 results.
Resolved: How to get the latest record in each group using GROUP BY?
posted by admin on May 21, 2016
Let's say I have a table called messages with the columns:

id | from_id | to_id | subject | message | timestamp


I want to get the latest message from each user only, like you would see in your FaceBook inbox before you drill down into the actual thread.

This query seems to get me close to the result I need:

SELECT * FROM messages GROUP BY from_id


However the query is giving me the oldest message from each user and not the newest.

I can't figure this one out.Read more
Resolved: Get data from table from a list of strings on MySQL
posted by admin on May 6, 2016
How can I query data from a table available on a list of strings?

I only want to get the data from the list of strings.

Example:
Table
ID Name
1 Big
2 Small
3 Extra
4 Orange
5 Drink



List of Strings:
Big
Small
Extra
Read more
Resolved: MySQL IN for all values
posted by admin on May 6, 2016
I have MySQL query, which contain IN clause

select ItemID
from ItemCategory
where CategoryID in (5,6,7,8)
group by ItemID


I need it to work like an AND across multiple rows.Read more
Resolved: Submit form on change of dropdown list
posted by admin on April 26, 2016
I have SELECT dropdown list

<form method="GET" >
<select id="id_period" name="period">
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
<option value="all" selected="selected">all time</option>
</select>
</form>

I want to submit form on changeRead more
Resolved: Yii CGridView get selected row event on shoose
posted by admin on April 23, 2016
as someone in another topic said, "I did my best to search for answers but didn't find the a solution".

First, I am newbie in Yii.

I have 2 frames, the 1st has a CGridView component that print data from MySql tables. My goal is when I click on a row in CGridView, let I know in the 2nd frame which rows where selected.

I have the CGridView with multiple selection, the frames, and read that selectionChanged is a "a javascript function that will be invoked after the row selection is changed. The function signature is function(id) where 'id' refers to the ID of the grid view. In this function, you may use $.fn.yiiGridView.getSelection(id) to get the key values of the currently selected rows."

My problem is, I don't know how to use selectionChanged function.Read more
Resolved: MySQL get most popular tags ids combination with their counts
posted by admin on April 18, 2016
I have three tables
1.tbl_tag

id int NOT NULL AI PK
name VARCHAR(50) NOT NULL

id name
1 lifestyle
2 store
3 car
4 luxury
5 classy
6 boy
7 girl
8 man
9 woman
10 strong
etc ...


2.tbl_media

id int NOT NULL AI PK
name VARCHAR(50) NOT NULL

id name
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
etc...


3. tbl_media_tag

id int NOT NULL AI PK
media_id int NOT NULL -> relationship with tbl_media
tag_id int NOT NULL -> relationship with tbl_tag

id media_id tag_id
1 1 4
2 1 3
3 4 3
4 5 2
5 6 8
6 4 4
7 8 7
8 7 4
9 7 3
10 6 2
11 8 4
12 8 3
etc...


I want to get most popular tags(tag_id) combinations with LIMIT, for example most popular top ten tags combination

I want to get result like this

4, 7, 3 (75)
4, 8 (42)
1, 7, 9, 10 (28)
7, 8, 9 (10)
7, 2 (2)
Read more
Resolved: Yii sum criteria select condition
posted by admin on April 15, 2016
I try to count my views sum count, by this way

$criteria=new CDbCriteria;
$criteria->select='SUM(visits) as SUMvisits';
$criteria->condition='media_id=:media_id';
$criteria->params=array(':media_id'=>$media_id);
$sBalance = Views::model()->find($criteria)->getAttribute('SUMvisits');
var_dump($sBalance);exit();


Something like this, but it is not workingRead more
Wiki: Attribute Equals Selector [name=”value”]wiki
posted by admin on April 12, 2016
Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.

jQuery( "[attribute='value']" )
attribute: An attribute name.

value: An attribute value. Can be either an unquoted single word or a quoted string.

Example:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>attributeEquals demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div>
<label>
<input type="radio" name="newsletter" value="Hot Fuzz">
<span>name?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Cold Fusion">
<span>value?</span>
</label>
</div>
<div>
<label>
<input type="radio" name="newsletter" value="Evil Plans">
<span>value?</span>
</label>
</div>

<script>
$( "input[value='Hot Fuzz']" ).next().text( "Hot Fuzz" );
</script>

</body>
</html>

Finds all inputs with a value of "Hot Fuzz" and changes the text of the next sibling span.Read more
Wiki: Yii 1.1 cgridview filter dropdown with relation table datawiki
posted by admin on April 7, 2016
View: admin.php

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'media-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'caption',
'created',
'updated',
array( 'name' => 'visibility_id',
'value' => '$data->visibility_id',
'filter' => CHtml::listData(Visibility::model()->findall(), 'id', 'name'),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>


Model: Visibility.php

class Visibility extends CActiveRecord
{
public function tableName()
{
return 'tbl_visibility';
}

public function rules()
{
return array(
//your rules here
);
}

public function relations()
{
return array(
'media' => array(self::HAS_MANY, 'Media', 'visibility_id'),
);
}

public static function model($className=__CLASS__)
{
return parent::model($className);
}
}


Model: Media.php

class Media extends CActiveRecord
{
public function tableName()
{
return 'tbl_media';
}
public function rules()
{
return array(
//your rules
//...

);
}
public function relations()
{
return array(
'visibility' => array(self::BELONGS_TO, 'Visibility', 'visibility_id'),
);
}

public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Read more
Resolved: Yii Dropdown List Empty Value as Default
posted by admin on April 7, 2016

<?php $type_list=CHtml::listData($galleries,'id','name'); ?>
<?php echo $form->dropDownList($model, 'gallery_id', $type_list); ?>


I want to add empty option to SELECT
In output, I want to get

<select name="sel" id="sel">
<option value="0">Choose Gallery</option>
...
</selected>
Read more