Tweet

Monday, 9 April 2012

onchange




<script type="text/javascript">
function show_form(selct_value){
var div = document.getElementById("forms");
var form = div.getElementsByTagName("form");
for (var i = 0; i < form.length; i++) {
    form[i].style.display = "none";
}
document.getElementById(selct_value+"_form").style.display = "block";
}
</script>


<select onchange="show_form(this.value)">
<option selected="selected">Select</option>
<option value="work_ex">Work Experience</option>
</select>


<form method="post" id="work_ex_form" style="display:none" action="insert_job_code.php">
<table align="center" cellpadding="2" cellspacing="2" border="2">
<tr>
<td align="center"><strong>Minimum Experience</strong></td>
<td align="center"><strong>Maximum Experience</strong></td>
</tr>
<tr>
<td><input type="text" name="mini_ex" value=""/></td>
<td><input type="text" name="maxi_ex" value=""/></td>
</tr>
<tr>
<td align="center" colspan="3"><input type="submit" name="work_ex" value="Submit" /> </td>
</tr>
</table>
</form>

Monday, 26 March 2012

selected dropdown


<?php
$indus = array("Pharma","REO","Biotech","FMCG","Dairy","Bev.","Soaps","Chemicals","Paint","Engg.","Oil/Gas","Auto","Sales/Marketing","Other");
for($i = 0;$i<count($indus);$i++):
?>
<option value="<?php echo $indus[$i] ?>"
<?php
if($indus[$i] == $user_data['current_inds']):
?>
selected="selected"
<?php
endif;
?>
><?php echo $indus[$i] ?></option>
<?php endfor; ?>

Sunday, 25 March 2012

Pagination Example


<?php
$connection = mysql_connect("localhost","root","");
$database = mysql_select_db('database');






$numOfRecordPerpage = 5;
$numofPage = 1;

if(isset($_REQUEST['page'])){
$numofPage = $_REQUEST['page'];
}

$start = ($numofPage-1)* $numOfRecordPerpage;

$query = mysql_query("select * from tablename limit $start,$numOfRecordPerpage");



echo "<table border='0' width='60%' bgcolor='lightgreen' align='center'>";
echo "<tr>";echo "<td>";echo "Name";echo "</td>";echo "<td>";echo "Age";echo "</td>";echo "<td>";echo "City";
echo "</td>";echo "<td>";echo "Salary";echo "</td>";echo "</tr>";
echo "<tr>";


while($result = mysql_fetch_array($query)){


echo "<td bgcolor='#ffffcc'>".$result['user_name']."</td>";
echo "<td bgcolor='#ffffcc'>".$result['user_age']."</td>";
echo "<td bgcolor='#ffffcc'>".$result['user_city']."</td>";
echo "<td bgcolor='#ffffcc'>".$result['user_salary']."</td>";
echo "</tr>";
}
echo "</table>";



$query = mysql_query("select * from tablename");
$totalNumofRecord = mysql_num_rows($query);


$maxPageNo = ceil($totalNumofRecord/$numOfRecordPerpage);
 
$self = $_SERVER['PHP_SELF'];


if($numofPage>1)

{
$currentPage = $numofPage-1;
$prvious = "<a href=\"$self?page=$currentPage\"><b>prvious</b></a>";
$first = "<a href=\"$self?page=1\"><b>First</b></a>";
}

else

{
$prvious = "Previous";
$first = "First";
}


if($numofPage<$maxPageNo)

{
$currentPage = $numofPage+1;
$next = "<a href=\"$self?page=$currentPage\"><b>next</b></a>";
$last = "<a href=\"$self?page=$maxPageNo\"><b>last</b></a>";
}

else

{
$next = "next";
$last = "last";
}
//echo $first." ".$prvious." ".$next." ".$last;


//echo $first."".$prev." ";
for($i=1;$i<=$maxPageNo;$i++)

{
     
 if($numOfPage == $i)

{
echo " "."<a href=\"$self?page=$i\"><b>$i</b></a>"." ";
}

   else
   {
echo " "."<a href=\"$self?page=$i\">$i</a>"." ";
   }
  }
 // echo " ".$next." ".$last;

?>

Tuesday, 20 March 2012

For Loop


<?php for($i = 0;$i<count($work);$i++):?>
<option value="<?php echo $work[$i]['minimum']; ?>"><?php echo $work[$i]['minimum']; ?></option>
<?php endfor;?>


<?php if($stool_data =  $while_tests['stoolexamination']){
$stool = (explode(",",$stool_data));
$stool_size = sizeof($stool);
for($st = 0;$st<$stool_size;$st++){
$sel_stool = "SELECT * FROM stoolexamination WHERE id ='$stool[$st]'";
$que_stool = mysql_query($sel_stool);
?>

Jquery Alert


<form id="submit">
<input type="submit" name="alert" value="alert">
</form>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$('#submit') .submit(function(){
alert('this is test alert');
return false;
})
</script>

Get Content Of Span With Id


<?php
$string = "<span id=\"lastPrice\">29.00</span>";
preg_match("/\<span id\=\"lastPrice\"\>([\d.]+?)\<\/span\>/",$string,$match);
print "<pre>";
echo $match[1];
//var_dump($match[1]);
print "</pre>";
?>
<?php
$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo "Number of days since '2006-07-01': $days";
?>

Jquery Form


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>1
<head>
<title>JQuery Form Example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script type="text/javascript">
$(document).ready(function(){
$("#myform").validate( {
debug: false,
rules: {
name: "required",
email: {
required: true,
email: true
}
},
messages: {
name: "Please let us know who you are.",
email: "A valid email will help us get in touch with you.",
},
submitHandler: function(form) {
// do other stuff for a valid form
$.post('process.php', $("#myform").serialize(), function(data) {
$('#results').html(data);
});
}
});
} );
</script>
<style>
label.error { width: 250px; display: inline; color: red;}
</style>
</head>
<body>
<form name="myform" id="myform" action="" method="POST">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" value=""/>
<br>
    <label for="email" id="email_label">Email</label>
    <input type="text" name="email" id="email" size="30" value=""/>
<br>
<input type="submit" name="submit" value="Submit">
</form>
<!-- We will output the results from process.php here -->
<div id="results"><div>
</body>
</html>