Friday, February 27, 2015

for converting database tables to utf 8 format

for converting database and its table to utf 8 format


ALTER TABLE tbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";

Thursday, February 26, 2015

iframe basics


 css for iframe

iframe {
    border: none;
    outline: none;
    overflow: hidden;
}



 <iframe src="http://192.168.1.82:8062/wordpress/wp-content/themes/Custom%20Theme/gallery.php" frameborder="0" width="100%" height="100%" scrolling="no" class="iframe"></iframe>

Tuesday, February 24, 2015

filter localised data from database

 eg


SELECT * FROM tb WHERE fieldname LIKE N'%avec%' ;

prefix 'N' in after like in sql query as The N stands for National language character set. 
<?php

$search=$_POST['search'];
$search=mysql_escape_string($q);
$search_rep=str_replace(" ","%",$search); // Space replacing with %
$sql=mysql_query("SELECT  *  FROM  tb  WHERE fieldname LIKE N'%$search_rep%'");
?>
<html>
<body>
<form method="post" action="">
<input type="text" name="q" /> <input type="submit" value=" Search " />
</form>
<?php
while($row=mysql_fetch_array($sql))
{
$title=$row['fieldname'];
echo '<div>'.$title.'</div>';
}
?>
</body>
</html>

Localisation full example

CREATE TABLE `tablename`
(
`id` int  NOT NULL AUTO_INCREMENT,
`fieldname` varchar(300) CHARACTER SET utf8 collate utf8_general_ci ,
`fieldname` varchar(300)   CHARACTER SET utf8 collate utf8_general_ci,
PRIMARY KEY (`id`)
)
delete user

<?php include("french.php"); ?>
<?php

$LANG ='fr';

$connect  =mysql_connect('192.168.1.170', 'user','aipl2014') or die(mysql_error());
mysql_select_db(test,$connect)or die("cannot select DB");

if(isset($_POST["submit"]) && $_POST["submit"]!="") {
$usersCount = count($_POST["userName"]);
for($i=0;$i<$usersCount;$i++) {
mysql_query("UPDATE packageimages set status='" . $_POST["firstName"][$i] . "' WHERE pimageid='" . $_POST["userId"][$i] . "'");
}
header("Location:need_Approval_list.php");
}
?>
<html>
<head>
<title><?php echo msg('UnApproved Packages'); ?></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="post" action="">
<div style="width:500px;">
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center">
<tr class="tableheader">
<td><?php echo msg('UnApproved Packages'); ?></td>
</tr>
<?php
$rowCount = count($_POST["users"]);
for($i=0;$i<$rowCount;$i++) {
$result = mysql_query("SELECT * FROM  ads WHERE adId='" . $_POST["users"][$i] . "'");
$row[$i]= mysql_fetch_array($result);
?>
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">
<tr>
<td><label><?php echo msg('path'); ?></label></td>
<td><input type="hidden" name="userId[]" class="txtField" value="<?php echo $row[$i]['adid']; ?>"><input type="text" name="userName[]" class="txtField" value="<?php echo $row[$i]['path']; ?>"></td>
</tr>
<tr>
<td><label><?php echo msg('status'); ?></label></td>
<td><input type="text" name="firstName[]" class="txtField" value="<?php echo $row[$i]['path']; ?>"></td>
</tr>
</tr>
</table>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
/body></html>


edit user


<?php include("french.php"); ?>
<?php

$LANG ='fr';

$connect  =mysql_connect('192.168.1.170', 'user','aipl2014') or die(mysql_error());
mysql_select_db(test,$connect)or die("cannot select DB");

if(isset($_POST["submit"]) && $_POST["submit"]!="") {
$usersCount = count($_POST["userName"]);
for($i=0;$i<$usersCount;$i++) {
mysql_query("UPDATE packageimages set status='" . $_POST["firstName"][$i] . "' WHERE pimageid='" . $_POST["userId"][$i] . "'");
}
header("Location:need_Approval_list.php");
}
?>
<html>
<head>
<title><?php echo msg('Approved Packages'); ?></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="post" action="">
<div style="width:500px;">
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center">
<tr class="tableheader">
<td><?php echo msg('Approved Packages'); ?></td>
</tr>
<?php
$rowCount = count($_POST["users"]);
for($i=0;$i<$rowCount;$i++) {
$result = mysql_query("SELECT * FROM  ads WHERE adId='" . $_POST["users"][$i] . "'");
$row[$i]= mysql_fetch_array($result);
?>
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">
<tr>
<td><label><?php echo msg('path'); ?></label></td>
<td><input type="hidden" name="userId[]" class="txtField" value="<?php echo $row[$i]['adid']; ?>"><input type="text" name="userName[]" class="txtField" value="<?php echo $row[$i]['path']; ?>"></td>
</tr>
<tr>
<td><label><?php echo msg('status'); ?></label></td>
<td><input type="text" name="firstName[]" class="txtField" value="<?php echo $row[$i]['path']; ?>"></td>
</tr>
</tr>
</table>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
</body></html>



Details

<?php include("french.php"); ?>

<?php

$LANG ='fr';

$connect  =mysql_connect('192.168.1.170', 'user','aipl2014') or die(mysql_error());
mysql_select_db(test,$connect)or die("cannot select DB");
?>
<html>
<head>
<title><?php echo msg('List for Approval'); ?></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script language="javascript" src="ok.js" type="text/javascript"></script>
</head>
<body>
<form name="frmUser" method="post" action="">
<div style="width:500px;">
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center">
<?php
$name = $_GET['image'];



$result = mysql_query("
select * from ads
");


$row[$i]= mysql_fetch_array($result);

?>
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">


<tr >

</td>
</tr>


<tr class="evenRow">
<td colspan=2><?php echo msg('List for Approval'); ?></td>
</tr>

<?php


$day = $_GET['image'];

$numCols = 2;

$result1 = mysql_query("

select * from ads ");

while($row2[$j] = mysql_fetch_assoc($result1))
{



?>





<?php
};

?>

<tr class="tableheader">
<td></td>
<td ><?php echo msg('path'); ?></td>



</tr>

<?php
$i=0;
while($row = mysql_fetch_array($result)) {
if($i%2==0)
$classname="evenRow";
else
$classname="oddRow";
?>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td><input type="checkbox" name="users[]" value="<?php echo $row["adid"]; ?>" ></td>
<td><?php echo $row["path"]; ?></td>

</tr>
<?php
$i++;
}
?>





</table>
</td>
</tr>
<?php

?>
<tr>
<td colspan="4"><input type="button" name="update" value="Approve" onClick="setUpdateAction();" /> <input type="button" name="delete" value="UnApprove"  onClick="setDeleteAction();" /></td>
</td>
</tr>
</table>
</div>
</form>
</body></html>

french.php


<?php
$messages = array (
    'fr'=> array('List for Approval' =>
           'Liste pour approbation ',
        'Approved Packages' =>
           'Emballages agréés ',
       'UnApproved Packages' =>
           'Packages unapproved ',
       'path' => 'Chemin',
       'status' => 'État'),

    'en_GB'=> array(
        'My favorite foods are' =>
            'My favourite foods are',
        'french fries' => 'chips',
        'biscuit' => 'scone',
        'candy' => 'sweets',
        'potato chips' => 'crisps',
        'cookie' => 'biscuit',
        'corn' => 'maize',
        'eggplant' => 'aubergine'
    )
   
);

function msg($s) {
    global $LANG;
    global $messages;
   
    if (isset($messages[$LANG][$s])) {
        return $messages[$LANG][$s];
    } else {
        error_log("l10n error:LANG:" .
            "$lang,message:'$s'");
    }
}
?>

 ok.js

function setUpdateAction() {
document.frmUser.action = "edit_user.php";
document.frmUser.submit();
}
function setDeleteAction() {
if(confirm("Are you sure want to unnaprove the following images?")) {
document.frmUser.action = "delete_user.php";
document.frmUser.submit();
}
}

code to view localisaed data from database with php

 CREATE TABLE `tablename`
(
`id` int  NOT NULL AUTO_INCREMENT,
`fieldname` varchar(300) CHARACTER SET utf8 collate utf8_general_ci ,
`fieldname` varchar(300)   CHARACTER SET utf8 collate utf8_general_ci,
PRIMARY KEY (`id`)
)

<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php


$query=mysql_connect("192.168.1.170","user","aipl2014");
mysql_select_db("test",$query);
mysql_query ("set character_set_results='utf8'");
$query = mysql_query("SELECT * FROM j") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
echo $row['title']; // Article
echo $row['description']; // Description
}
?>
</html>

Code to insert special character(for localisation) in php


CREATE TABLE `tablename`
(
`id` int  NOT NULL AUTO_INCREMENT,
`fieldname` varchar(300) CHARACTER SET utf8 collate utf8_general_ci ,
`fieldname` varchar(300)   CHARACTER SET utf8 collate utf8_general_ci,
PRIMARY KEY (`id`)
)

<?php
$query=mysql_connect("192.168.1.170","user","aipl2014");
mysql_select_db("test",$query);
if(isset($_POST['submit']))
{
$description=$_POST['description'];
$day=$_POST['day'];
$origin=$_POST['origin'];
$destination=$_POST['destination'];
$flightnumber=$_POST['flightnumber'];
$frequency=$_POST['frequency'];
$Departure=$_POST['Departure'];
$arrival=$_POST['arrival'];


$query1=mysql_query("insert into packageoffers(description , days ,origin , destination , flightNumber ,frequency , departure , arrival  ) values('$description','$day','$origin','$destination','$flightnumber','$frequency','$Departure','$arrival')");

if($query)
{
echo "Travel Package offers successfully submitted  ";// to move to another page use header("location:index.php");
}
else
{
echo "There is a problem in user registration, Please try again ";
}
}
?>
<fieldset style="width:275px;">
<h3>Please submit Package offers </h3>
<form method="post" action="insert.php">



Description: <input  type="text" name="description" /><br>
Day: <input  type="text" name="day" /><br>
Origin: <input  type="text" name="origin" /><br>
Destination: <input  type="text" name="destination" /><br>
FlightNumber: <input  type="text" name="flightnumber" /><br>
Frequency: <input  type="text" name="frequency" /><br>
Departure: <input  type="text" name="Departure" /><br>
arrival: <input  type="text" name="arrival" /><br>





   
<input type="submit" name="submit">

   
  
</form>
</fieldset>