post

PHP: Find maximum odd number of sequence in an array

This is php program that finds the maximum odd number of sequence in an array. By editing, in case of even number also be found out.

Code:
[php]
<?php
$x = array(1,7,4,5,7,5,6,3,4,6,87,53,45,567,45,43,66,56,57,5);
$tot = count($x);
$y = $res = array();
$y[0] = array();
$k = $j = 0;
for($i = 0; $i $val)
if($max == count($val))
$k = $key;

echo “The number of maximum odd sequesnce: $max
The numbers are:”;
var_dump($y[$k]);

?>
[/php]

Waiting for any better solutions. :)

post

A little trick to store data into mysql database from a large form

Sometimes we feel boring to write mysql insertion query to store data into database from a large form where are too many input fields (such as about 50 fields). We face problem to handle all the fields, sometimes we miss the field name. Here is a small trick to store data from such a large form.

In this trick, we have to do same naming of table fields and input fields. For example –

[html][/html]

Then the field name of the database will be “first_name”

Then the php code will be:

Suppose, name of the submit button is submit [html][/html]

[php]
safe_entry($_POST); // here obj is the object; safe_entry is a custom function which confirms the input validation of XSS and mysql injection; otherwise you can use $data = safe_entry($_POST); or simply use $data = $_POST;

$field = $value = array(); //two blank array in which field names and field values will be stored

foreach($data as $key=>$val)

if($key != ‘submit’)

{

array_push($field, $key);

array_push($value, $val);

}

$fields = implode(‘,’, $field);

$values = implode(“‘, ‘”, $value);

$sql = “insert into tablename($fields) values(‘$values’)”;

$query = $obj->insertQuery($sql); //use direct function mysql_query() in stead of custom function and object

?>
[/php]

That’s it! This code will store data from a large form. Thanks.

post

jSlider Plugin for jQuery (for 3 horizontal div)

This is my first jQuery plugin. Not so perfect, but it can be used I think :)

This plugin is very easy to use.

Doc:
This is a small slider content plugin for three horizontal floated div. By clicking on top menu, the divs switch.

1. Just pass the master div id which is wrapping the three floating div in the parameter field named master.
2. Pass id of the three floated divs’ in label parameter under jid index
3. Pass id of the three links’ in label parameter under links index

That’s It!
You don’t have to mention floated div in css.

Javascript Code:
[html]

$(document).ready(function(){
$.fn.jSlider({
//”width”:null,
//”height”:null,
“master”:”content”,
“labels”:[
{“jid”:”one_content”, “links”:”one”},
{“jid”:”two_content”, “links”:”two”},
{“jid”:”three_content”, “links”:”three”},
]
});
});

[/html]

HTML Code:
[html]

This is DIV 1

This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1. This is DIV 1.

This is DIV 2

This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2. This is DIV 2.

This is DIV 3

This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3. This is DIV 3.

[/html]

CSS Code:
[css]

#wrapper{
width:100%;
overflow:hidden;
color:#990000
}

#header{
width:100%;
height:30px;
background:#0033FF;
color:#FFFFFF;
}

#content{
overflow:hidden;
}

#header a{
padding:5px 15px;
color:#FFFFFF;
}

#one_content{
background:url(images/one.jpg) repeat;
}

#two_content{
background:url(images/two.jpg) repeat;
}

#three_content{
background:url(images/three.jpg) repeat;
}

[/css]

That’s it !