Archive

Archive for November, 2008

CodeIgniter How to Pagination

November 12th, 2008 3 comments

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.

CodeIgniter’s Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.

If you are not familiar with the term “pagination”, it refers to links that allows you to navigate from page to page, like this:

« First < 1 2 3 4 5 > Last »

function shownews()
{
if($this->userlib->logged_in()) 
//checking for security purposes
{
$this->load->library('pagination');
$per_page = 10; 
// How many pages you want to show in each page
$total = $this->db->get('posts', $per_page, $this->uri->segment(3)); 

//Here is the most important part actually. 
Basically $total variable determined which 
rows you are going to show in the page

$config['base_url'] = base_url().'/index.php/admin/shownews';
$config['total_rows'] = $this->db->count_all('posts'); // Count total rows in the query
$config['per_page'] = $per_page;
$config['num_links'] = 6;
$this->pagination->initialize($config);
$data['posts'] = $total;
$this->load->view('admin_shownews', $data);
} else {
$this->load->view('admin_logineed');
}
}

After getting done with this configuration part of pagination class all you have to do is just initialize it like you are doing it in most of programming languages.

Read more…

VN:F [1.9.22_1171]
Rating: 7.1/10 (41 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 5 votes)

Tutorial #3 – Pizza Order in C#

November 11th, 2008 1 comment

Here is my new pizza order tutorial for you. In this tutorial you are able to control checkboxes and radiobuttons together and show them into a message box window.

Codes below…

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class pizza : Form
{

//Some global strings to keep radiobutton and checkbox events text's.
private String a1 = null;
private String a2 = null;
private String a3 = null;
private String menu = null;

public pizza()
{
InitializeComponent();
}

Read more…

VN:F [1.9.22_1171]
Rating: 5.9/10 (9 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)
Categories: C#, Programming Tags: , , ,

Tutorial #2 – Basic Guess Game in C#

November 10th, 2008 No comments

Here is my new tutorial for you about C#. In this tutorial i am going to make a little game about guessing result of some number summation, multiplation, division and addition. And i am going to focus on handling the enter keypress event for textfield.

Here as you see from the screenshot of the main window a user should guess the result of this operation. Textbox1 equals the random number “96″, textbox2 equals the random number “73″ and there is an randomly operator which is “-” . User should guess this result and should write down the guess into the textbox3 field. When user press enter button textbox3 handles this event.

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13) //Char 13 handles the enter key
{
Console.WriteLine(total);  //Here i can check the result from console for testing purposes
if (total.ToString() == textBox3.Text)
{
StringBuilder dogru_str = new StringBuilder();
dogru_str.Append(textBox1.Text);
dogru_str.Append(" " + label1.Text + " ");
dogru_str.Append(textBox2.Text + " = ");
dogru_str.Append(total + "\n");
dogru_str.Append("Your answer was correct...");
MessageBox.Show(dogru_str.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

Read more…

VN:F [1.9.22_1171]
Rating: 9.8/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)

Tutorial #1 – Random Function in C#

November 9th, 2008 No comments

Since there are some other ways as well. Here is my little function which can generate a random integer

private int RandomNumber(int min, int max)
{
Random random = new Random();
int rand = random.Next(min, max);
return rand;
}

I need to convert this interger number to a string. And this function takes to parameters minimum & maximum. That helps you to determine the interval of this random numbers.

//Determine about operator
String[] operators = { "+", "-", "/", "*" };
int rand3 = random.Next(1, 5);
//Console.WriteLine(rand3.ToString());
switch (rand3.ToString())
{
case "1":
label1.Text = "+";
total = rand1 + rand2;
break;
case "2":
label1.Text = "-";
total = rand1 - rand2;
break;
case "3":
label1.Text = "/";
total = rand1 / rand2;
break;
case "4":
label1.Text = "*";
total = rand1 * rand2;
break;
default:
label1.Text = "Error";
break;
}

Read more…

VN:F [1.9.22_1171]
Rating: 1.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Categories: C#, Programming Tags: , ,

Java ActionListener Tutorial

November 6th, 2008 No comments

This tutorial has two classes. ActionListener and Main class are seperated from each other.

  • ParamListener.java
  • BtnsListener.java

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* ParamListener.java
*/
public class ParamListener extends JFrame{
public ParamListener() {
JButton btn10 = new JButton("10");
JButton btn20 = new JButton("20");
JButton btn30 = new JButton("30");
JButton btn40 = new JButton("40");

btn10.addActionListener( new BtnsListener ("ten"));
btn20.addActionListener( new BtnsListener ("twenty"));
btn30.addActionListener( new BtnsListener ("thirty"));
btn40.addActionListener( new BtnsListener ("fourty"));

JPanel content = new JPanel();
content.add(btn10);
content.add(btn20);
content.add(btn30);
content.add(btn40);

setContentPane(content);
setTitle("A Tutorial");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();
}

public static void main(String[] args) {
new ParamListener();

}

}

Read more…

VN:F [1.9.22_1171]
Rating: 1.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Categories: Java Tags: , , ,