Because I didn’t found any example of Yii autocomplete function. particularly showing how to fetched data via a server request.
For the widget function in view:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'username',
'value' => $model->username,
'sourceUrl' => array('user/getusername'),//path of the controller
'options' => array(
'minLength' => '1', // min chars to start search
'select' => '' // when the value selected
),
));
Now, we start create the
getusername action in the
UserController file.
In here, I am showing you how to use TideSDK to connect MySQL Database with PHP in your applicaion.
Example Data
The example data in this post uses as below.
CREATE TABLE fruits (`id` int, `name` varchar(50));
INSERT INTO fruits (`id`, `name`)
VALUES (1, 'Apple'),
(2, 'Durian'),
(3, 'Banana'),
(4, 'Lemon'),
(5, 'Pear'),
(6, 'Star fruit'),
(7, 'Strawberry'),
(8, 'Orange');
After that we need create a connection string with the Database. Save the code below as
conn.php and put it inside the
Resources folder.
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('foo', $conn);
In ASP MVC4 Appliction I can add a cshtml file in
app_code folder like below so that I can use my custom helper method in another cshtml.
App_Code/MyHelpers.cshtml
@helper LabelExtensions(string input) {
"<pre>@input</pre>"
}
Using the Helper in a Page.
<p>This is some paragraph text.</p>
@MyHelpers.LabelExtensions("My Test Label.")
<p>This is some paragraph text.</p>
Output:
<p>This is some paragraph text.</p>
<pre>My Test Label.</pre>
<p>This is some paragraph text.</p>
But if the helper is classes (cs file) then you are not allow call the helper function like above. Below example show you how to use it in a Page.
When linking to posts or images from your posts, there is a more versatile means of doing so. Imagine that you change themes or move to another domain. You need to go through entire posts to search and replace every link.
Maybe you will think linking the posts or images like below example:
<a href="../contact/" >Contact Us</a>
But it was bad way.
This is worse as well:
<a href="http://chevronscode.com/contact/" >Contact Us</a>
Tables or result sets sometimes contain duplicate records. Sometimes, it is allowed but sometimes it is required to stop duplicate records. Sometimes, it is required to identify duplicate records and remove them from the table. This chapter will describe how to prevent duplicate records occurring in a table and how to remove already existing duplicate records.
You are allow use
PRIMARY KEY or
UNIQUE Index on a table with appropriate fields to stop duplicate records. Let’s create an example table with
id and
name as Primary Key:
CREATE TABLE `foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`value` int(11) NOT NULL,
PRIMARY KEY (`id`, `name`),
);
Posted by
chevrons in
MySQL
There may be times when a specific order is required in a SQL query which cannot be done using either ASC or DESC or using a special sort field. MySQL has a ORDER BY FIELD function which can be used to do this.
Example Data
The example data in this post uses as below. This is a somewhat simple table but it can be used to illustrate the point in this post quite well.
CREATE TABLE fruits (`id` int, `name` varchar(50));
INSERT INTO fruits (`id`, `name`)
VALUES (1, 'Apple'),
(2, 'Durian'),
(3, 'Banana'),
(4, 'Lemon'),
(5, 'Pear'),
(6, 'Star fruit'),
(7, 'Strawberry'),
(8, 'Orange');
Posted by
chevrons in
MySQL
To highlighter table row when user click the row. The easy way was add a css class on table “tr”.
How to add a css on “tr”? you need used JQuery to perform this action.
Before that, you need a table like below:
<div id="gridview">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
<tr>
<td>Row 4</td>
</tr>
</table>
</div>
And then add the “
highlighted” css class as well
.highlighted {
color: #261F1D
background-color: #E5C37E;
}
In prepping the new site design for my client, I need to show the total number of search results on my search page.
From the wordpress Forum I found 1 of the solution. Like the below example code.
$mySearch =& new WP_Query("s=$s & showposts=-1");
$num = $mySearch->post_count;
echo $num. "results";
But unfortunately, sometimes it still gave me the wrong count.
Below example showing you how to add the row number in WebGrid.
You just need add the following script inside the grid columns.
grid.Column(header: "No.",
format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex)
Not all content container blocks start with a tag element tag, though, and there are scenarios where the Razor parser cannot implicitly detect a content block.
Razor addresses this by enabling you to explicitly indicate the beginning of a line of content by using the @: character sequence within a code block. The @: sequence indicates that the line of content that follows should be treated as a content block:
@if (someCondition) {
@: Some content to display...
}
For more practical example, the below snippet demonstrates how we could output a "Not Stock" message to our product if numbers of product is zero.
@model.product_name
@if (model.unit_stock == 0) {
@: Not Stock
}
Because I am not wrapping the "Not Stock" message in an HTML tag element, Razor can’t implicitly determine that the content within the @if block is the start of a content block. We are using the @: character sequence to explicitly indicate that this line within our code block should be treated as content.