Saturday, December 6, 2014

Specify different error level reporting:

<?php
// Turn off error reporting
error_reporting(0);

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

Friday, December 5, 2014

City State Country Find thorw XML DATA

 <input type="text" placeholder="Enter your Location" class="enteryrsrch martop15" id="citystate" value="" name="citystate" autocomplete="off">

<script>
var pagereload = $.ajax({
    url:"<?=$url;?>",
    async: false
    }).responseText;
var element=$("#citystate")[0];
var options = {
    componentRestrictions: {country: 'IN'},
    types: ['geocode']
};
var autocomplete = new google.maps.places.Autocomplete(
    element,
    options
);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
   
    if(funcheckheader())
    {
            var statelongname = $("#state_long_name").val();
            var citylongname = $("#city_long_name").val();           
            var localitylongname = $("#locality_long_name").val();           
            var country = $("#country_long_name").val();
            var formatted_address = $("#citystate").val();
            $.ajax({
                type:"POST",
                url:"<?php echo base_url();?>index.php/dashboard/checkingcityid",
                data: 'city12='+citylongname+'&state12='+statelongname+'&country12='+country+'&localitylongname='+localitylongname+'&formatted_address='+formatted_address,
                success: function(data){
                    window.location = self.location;
                }
            })           
    }
        });

function funcheckheader()
{
 var flag=false;
 var pageurl="https://maps-api-ssl.google.com/maps/api/geocode/xml?address="+$("#citystate").val()+"&amp;sensor=false&amp;client=gme-kickzag&amp;signature=VF930KLrbu98sKKLqIjn4adIoTs=";

//alert(pageurl);

  var xmltest = $.ajax({
                type: "GET",
                url:pageurl,
                dataType: "xml",
                async: false,
                //success: parseXml
                }).responseText;

   
   var xml = jQuery.parseXML(xmltest);
           
            $(xml).find('GeocodeResponse').each(function(){
            var status = $(this).find('status').text();
           
            if(status=="OK")
            {
                var location_type = $(this).find('location_type').text();

                var formatted_address = $(this).find('formatted_address').text();

                    $("#formatted_address").val(formatted_address);

               
                         flag=true;

                         var i=1

                          $(this).find('result').each(function()
                            {
                             
                              if(i==1)
                                {
                                 $(this).find('address_component').each(function(){
                                 var type = $(this).find('type').text();

                                            if(type=="street_number")
                                            {
                                                var street_number = $(this).find('long_name').text();

                                                $("#street_number").val(street_number);
                                            }

                                            if(type=="route")
                                            {
                                                var street_name = $(this).find('long_name').text();

                                                $("#street_name").val(street_name);
                                            }
                                            if(type=="countrypolitical")
                                            {
                                                var country_long_name = $(this).find('long_name').text();
                                                var country_short_name = $(this).find('short_name').text();
                                                 //alert(country);
                                                 $("#country_long_name").val(country_long_name);
                                                 $("#country_short_name").val(country_short_name);
                                            }
                                            if(type=="localitypolitical")
                                            {
                                                var locality_long_name = $(this).find('long_name').text();
                                                var locality_short_name = $(this).find('short_name').text();
                                                 //alert(country);
                                                 $("#locality_long_name").val(locality_long_name);
                                                 $("#locality_short_name").val(locality_short_name);
                                            }
                                            if(type=="administrative_area_level_1political")
                                            {
                                                var state_long_name = $(this).find('long_name').text();
                                                var state_short_name = $(this).find('short_name').text();

                                                $("#state_long_name").val(state_long_name);
                                                $("#state_short_name").val(state_short_name);
                                            }
                                            if(type=="administrative_area_level_2political")
                                            {
                                                var city_long_name = $(this).find('long_name').text();
                                                var city_short_name = $(this).find('short_name').text();
                                                //alert(country);
                                                $("#city_long_name").val(city_long_name);
                                                $("#city_short_name").val(city_short_name);
                                            }
                                            if(type=="postal_code")
                                            {
                                                var postal_code = $(this).find('long_name').text();
                                                $("#postalcode").val(postal_code);
                                            }       
                                    });   
                                    i++;                                   
                                    flag=true;
                                  }
                                  else
                                {
                                      //alert('396');
                                    flag=true;
                                }
                            });
            }
            else
            {
                flag=false;
            }

           

    });
    return flag;
}

Wednesday, April 27, 2011

Delete Data In a Database

Delete Data In a Database

The DELETE FROM statement is used to delete records from a database table.

Syntax

DELETE FROM table_name
WHERE some_column = some_value

Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!To learn more about SQL, please visit our SQL tutorial.
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

Look at the following "Persons" table:
FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
The following example deletes all the records in the "Persons" table where LastName='Griffin':
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("DELETE FROM Persons WHERE LastName='Griffin'");

mysql_close($con);
?>

Update Data In a Database

Update Data In a Database

The UPDATE statement is used to update existing records in a table.

Syntax

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!To learn more about SQL, please visit our SQL tutorial.
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

Earlier in the tutorial we created a table named "Persons". Here is how it looks:
FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
The following example updates some data in the "Persons" table:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("UPDATE Persons SET Age = '36'
WHERE FirstName = 'Peter' AND LastName = 'Griffin'");

mysql_close($con);
?>
After the update, the "Persons" table will look like this:
FirstName LastName Age
Peter Griffin 36
Glenn Quagmire 33

The ORDER BY Keyword

The ORDER BY Keyword

The ORDER BY keyword is used to sort the data in a recordset.
The ORDER BY keyword sort the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.

Syntax

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
To learn more about SQL, please visit our SQL tutorial.

Example

The following example selects all the data stored in the "Persons" table, and sorts the result by the "Age" column:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons ORDER BY age");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'];
  echo " " . $row['LastName'];
  echo " " . $row['Age'];
  echo "<br />";
  }

mysql_close($con);
?>
The output of the code above will be:
Glenn Quagmire 33
Peter Griffin 35


Order by Two Columns

It is also possible to order by more than one column. When ordering by more than one column, the second column is only used if the values in the first column are equal:
SELECT column_name(s)
FROM table_name
ORDER BY column1, column2

The WHERE clause

The WHERE clause is used to extract only those records that fulfill a specified criterion.

Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name operator value
To learn more about SQL, please visit our 
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

The following example selects all rows from the "Persons" table where "FirstName='Peter':
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
?>
The output of the code above will be:
Peter Griffin

Select Data From a Database Table

Select Data From a Database Table

The SELECT statement is used to select data from a database.

Syntax

SELECT column_name(s)
FROM table_name
To learn more about SQL, please visit our SQL tutorial.
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

The following example selects all the data stored in the "Persons" table (The * character selects all the data in the table):
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

mysql_close($con);
?>
The example above stores the data returned by the mysql_query() function in the $result variable.
Next, we use the mysql_fetch_array() function to return the first row from the recordset as an array. Each call to mysql_fetch_array() returns the next row in the recordset. The while loop loops through all the records in the recordset. To print the value of each row, we use the PHP $row variable ($row['FirstName'] and $row['LastName']).
The output of the code above will be:
Peter Griffin
Glenn Quagmire


Display the Result in an HTML Table

The following example selects the same data as the example above, but will display the data in an HTML table:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

echo "<table border='1'>
<
tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
The output of the code above will be:
Firstname Lastname
Glenn Quagmire
Peter Griffin