Web Masters Site All For Web Masters

4Oct/110

Delete Duplicate Rows In Mysql With PHP

$dupq = mysql_query("SELECT * FROM `db`");
$dups = mysql_fetch_array($dupq);
foreach($dups as $dup){
mysql_query("DELETE FROM db WHERE duplicate_COLUMN='".$dup['duplicate_column']."' AND id!='".$dup['id']."'");
}

duplicate_COLUMN - Name of column and $dup['column_name'] delete duplicates which include same column data.

Filed under: MySQL, PHP, Programming No Comments
12Jan/110

Geotargeting with PHP

Its really important some time to use geo targeting for your web site users for example if you have e-commerci  site or for any other sites, I'll show example which give you opertunety to use geo ip with php scrip lets start.

13Aug/080

Read From Files In PHP

Read from open file can be done with function fread

  • string fread(int file, int length)

This function returning string with size of length from file which you want to read, for example

<?
 
$file = fopen("c:\file.txt", "r"); // File which must be opened
 
if(!$file) //if file have not been loaded
 
{
 
echo "Error";
 
}else{
 
$buff = fread($file, 100); // Read from $file(file.txt) maximum 100 characters
 
print $buff; // Print content of file which was read
 
}
 
?>
Filed under: PHP, Programming No Comments
28May/080

JavaScript And PHP

For example you want to use javascript in php and want to get for example alert message with this javascript code

<strong><script language="Javascript">alert ("This is a Javascript Alert")</script>

Now how to use it in echo here is example

echo"
<script language=\"Javascript\">alert(\"This is a Javascript Alert\")</script>";
Filed under: PHP No Comments
29Apr/080

PHP File Upload

This is small example for beginners, how to upload files with PHP, this method is very simple and it can be used at every server which supports PHP. We will use 2 files upload.html, and upload.php, by default files uploaded in /upload directory, make sure that upload directory is writable.

upload.html

<html>
<body>
 
      <form action='upload.php' method='post' enctype='multipart/form-data' />
      <input type='file' name='filename' /><br />
      <input type='submit' value='submit' /><br />
      </form>
 
</body>
</html>

upload.php

<?
//Test file size which must not be more then 3MB
if($_FILES['filename']['size'] > 1024*3*1024)
{
echo "File is more then 3MB!";
exit;
}
 
//Test File Input
if($_FILES['filename']['name'] == ''){ 
 
echo "You must browse the file!";
 
}else{
 
//If file pointed start Upload In /upload Path
 
if(move_uploaded_file($_FILES['filename']['tmp_name'], "upload/" .$_FILES['filename']['name'])){ 
         	echo "File Uploaded!";
}else{
        	echo "Can't upload file!";
}// End of Upload Code
 
}
 
?>
Filed under: PHP, Programming No Comments