Tweet

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>

Star Loop


<?php
$levels = 10;
$output = array();
for ($i = 1; $i <= $levels; $i = $i + 2) {
/*echo $i;
 echo "<br>";*/
$whitespace = ($levels - $i / 2);
 echo "<br>";
 $output[] = str_pad('', $whitespace, "-") . str_pad('', $i, '*');
}
/*echo "<pre>";
print_r($output);*/
echo implode("<br>", $output);
echo "<br>";
echo implode("<br>", array_reverse($output));
/*echo"<pre>";
print_r(array_reverse($output));*/
echo "<br>";
?>

Oops Lover


<?php
@session_start();
@ob_start();
//class created
class user_handler{
//function created for insert into table
function insert_data($userdata,$table){
$user_field = implode(",",array_keys($userdata));
$user_value = implode("','",array_values($userdata));
echo $insert = "INSERT INTO $table($user_field) VALUES('$user_value')";
$insert_que = mysql_query($insert) or die(mysql_error());
if($insert_que){
header("location:./enter_job_detail.php");
}
else{
header("location:./enter_job_detail.php");
}
}
function login($username,$password,$table){
$user_name = "SELECT * FROM $table WHERE username = '$username' AND password = '$password'";
$login_sql = mysql_query($user_name) or die(mysql_error());
$check = mysql_num_rows($login_sql);
if($check>0){
$fetch_login = mysql_fetch_array($login_sql);
$_SESSION['login'] = $fetch_login['id'];
header("location:./home.php");
//echo"enter";
}
else{
header("location:./index.php");
//echo"not enter";
}
}
function fetch_data($table){
$select_data  = "SELECT * FROM $table";
$fetch_que    = mysql_query($select_data);
//$fetch_data   = mysql_fetch_array($fetch_que);
$fetch_data   = array();
while($row    = mysql_fetch_assoc($fetch_que)){
$fetch_data[] = $row;
}
return $fetch_data;
}
function update_data($userdata,$table,$id){

$update_detail = "UPDATE $table SET ";
$flag = 0;
foreach($userdata as $key=>$value){
if($flag){
$update_detail .= ",";
}
$update_detail .= $key."='".$value."'";
$flag = 1;
}
$update_detail .=" WHERE id = '$id'";
$sql_update = mysql_query($update_detail);
}
}

Mail Form


if(isset($_REQUEST['submit'])){
  $location=$_SERVER['HTTP_REFERER'];
  $cleanedFrom = $_REQUEST['name'];


$to ='sonia@intiger.in';
$subject = 'Contact Us';

$headers = "From: " . $cleanedFrom . "\r\n";
       $headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message= '<html><body>';

  $message .= '<table rules="all" style="border-color: #E3E3E3;" cellpadding="10" width="450">';
$message .= "<tr style='background: #0268aa; color: #989898;'><td colspan='2'><strong>Path Lab</strong></td></tr>";
$message .= "<tr><td><strong>Name:</strong> </td><td>" .$_POST['name'] . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $_POST['email'] . "</td></tr>";
$message .= "<tr><td><strong>Phone:</strong> </td><td>" . $_POST['phone'] . "</td></tr>";
   $message .= "<tr><td><strong>Comment:</strong> </td><td>" . $_POST['comment'] . "</td></tr>";


   $message .= "<tr style='background: #0268aa;'><td colspan='2'>&nbsp;</td></tr>";
$message .= "</table>";
$message .= "</body></html>";


           
      $send =    mail($to, $subject, $message, $headers);

if($send)
{
echo "<script> alert('Message Sent. Thank you') </script>";
echo "<script> window.location = 'contact_us.php' </script>";
}

else
{
echo "<script> alert('Message Not Sent. Please try again') </script>";
echo "<script> window.location = 'contact_us.php' </script>";
}
     }