Pages

Showing posts with label list. Show all posts
Showing posts with label list. Show all posts

Sunday, April 5, 2015

Cakephp 3.0-Where IN Condition with list

So here comes Cakephp 3.0 with all new syntax new ORM and many other changes.I find myself struggling with Cakephp this hard since I used cakephp 1.3 for the first time.

But here is My first struggle to help you with

  return $this->find('list',['keyField' => 'id', 'valueField' => 'name'])->where([  
          'id IN'=>$nearCitys  
       ])->toArray();  

Sunday, August 18, 2013

MYSQL-Find a word from comma separated list(in string)

I have a table as follows

id name status
1  test1  option1,option2
2  test2  option,option1
3  test3  option2,option3
4  test4  option3,option4
5  test5  option1,option3

"SELECT * FROM TABLE WHERE FIND_IN_SET('option',status-name of column/attribute)">0

simple query to check whether a string is present in comma separated values entered as string under a column or attribute

Thursday, November 8, 2012

WordPress $post Variable Keys

WordPress $post Variable Keys
Below are the methods of retrieving the information that you are most likely to need.
  • $post–>ID – ID of the current post.
  • $post–>post_category - Retrieves the ID of the post category.
  • $post–>post_parent - ID of the page parent. Useful for creating custom navigational elements.
  • $post–>post_title – Post Title
  • $post–>post_excerpt - Post excerpt
  • $post–>post_content – Retrieves all of the post content, along with any markup.
  • $post–>post_name – Retrieving the slug of a post.
  • $post–>guid – Post Url
  • $post–>post_author – ID of post author post_parent
  • $post–>post_type - Returns the type, page or post.
  • $post–>menu_order - Returns the menu order as set in the post/page editing window. Often menu items are sorted via this value.
  • $post–>post_date - Retrieves the integer timestamp for when the post was published. The output can be customized. See the php.net date manual.
  • $post–>post_modified - Retrieves the integer timestamp for when the post was last modified.
  • $post–>post_status - Retrieves one of five possible posts statuses: publish, private, draft, pending, future.
  • $post–>comment_count - Returns the number of comments, pings, and trackbacks for a given post.
 And here is how to use it

 <?php if (have_posts()) : while (have_posts()) : the_post();  
 //somewhere in the loop  
 $yourvariable = $post->post_content;  
 //do something  
 endwhile; endif; ?>  

Thursday, August 11, 2011

Dynmically creating a table using Javascript and adding rows to it

For this you need to first of all define an empty html table element with an id property at least to refer to it my dummy was.
table
tr
th /th
th /th
/tr
tr
td /td
td /td
/tr
/table

Written without tags so that it is not interpreted by blog as html.

My table has a header row and a normal row

The table rows starts from index 0.You can use following code from a js file or directly on an html file.
(I recommend js file helps in re usability of code)

var tbl=document.getElementByid('tbl');
//Get the last row

var lastrow=tbl.rows.length

//since I already have a header row in my table and a row manually added so in my case //new row will be equal to last row (table length does not includes the last row)

var iteration=lastrow;
//create a new row
row=tbl.insertRow(lastrow);

//leftcell
//general text node to show the Sno's
var cellleft=row.insertcell(0);
var textnode=document.CreatetextNode(value of the node);
cellleft.appendChild(textnode);

//rightcell
//creation of a textbox node
var cellright=row.insertCell(1);
var el=document.CreateElement('input');
el.type='text';
el.name='name';
el.id='id';
cellright.appendChild(el);

you can add more columns by incrementing index in var cellright=row.insertCell(1);

One of my columns required to create a list dynamically..since I need the whole list and so I cloned the same from my first row(it was the only need for which I had to create a row manually)

To clone an element use the following
elsource=document.getElementById('list element');
eldestination=elsource.clone();
eldestination.name='new list name'
eldestination.id='new id'

So that's how we can dynamically add rows to a table....

Sunday, June 26, 2011

Cakephp:Selecting Multiple Entries from a list

use the following code

$this->Form->select('Model.name',$listarray,'selectedvalue',array('multiple'=>'multiple','size'=>'5');