0

i have two input fields for example(A and B) whose values are coming through database, the value of field B depend upon the value of A. I am using ajax call to change the values of input field B. here is my code:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
    function ajaxfunction(parent)
    {
        $.ajax({
            url: 'http://localhost/test/process.php',
            data: { vall : parent }, 
            success: function(data) {
                $("#sub").html(data);
            }
        });
    }
</script>
</head>

<body>
<select onchange="ajaxfunction(this.value)">
<?php 
$q= mysql_query("select * from tab1");
while ($row= mysql_fetch_array($q)){
$name= $row['name'];    
echo '

<option value="'.$name.'"> '.$name.' </option>
';
}
?>
</select>

<select id="sub"></select>

</body>
</html>

and my process.php was:

$e =$_GET['vall'];
echo $e;
    $result = mysql_query("SELECT * FROM tab2 WHERE name = '".$e."' ");
    while(($data = mysql_fetch_array($result)) !== false)
        echo '<option value="', $data['id'],'">', $data['lname'],'</option>'

It is working fine for me. Now the problem is I am working in classes and I want to get the value in a function, Now i have the following structure of process.php

    class location{ 

    public function getlocation($e)
        {

            $sql="SELECT * FROM tab2 WHERE name = '".$e."'";
            return $this->objConnect->GetData($sql);
        }
public function GetallpropertyFeatured(){ 

        $sql="select * from sale_property WHERE category='Featured' AND accept_status='Active'  ORDER BY property_id DESC  ";   
        return $this->objConnect->GetData($sql);
    }//for showing all propery on the base of recent status.
    public function GetallpropertyRecent(){ 

        $sql="select * from sale_property WHERE category='Recent' AND accept_status='Active' ORDER BY property_id DESC  ";  
        return $this->objConnect->GetData($sql);
    }//for showing all propery on the base of trending status.
    public function GetallpropertyTrending(){ 

        $sql="select * from sale_property WHERE category='Trending' AND accept_status='Active' ORDER BY property_id DESC  ";    
        return $this->objConnect->GetData($sql);
    }
    //for Getting propery on the base of featured status.
    public function GetpropertyByFeatured(){ 

        $sql="select * from sale_property WHERE category='Featured' AND accept_status='Active' ORDER BY property_id DESC  ";    
        return $this->objConnect->GetData($sql);
    }
    //for Getting propery on the base of latest status.
    public function GetpropertyByRecent()
    {
            $sql="select * from sale_property WHERE category='Recent' AND accept_status='Active' ORDER BY property_id DESC ";
        return $this->objConnect->GetData($sql);
    }
    //for Getting propery on the base of trending status.
    public function GetpropertyByTrending()
    {

        $sql="select * from sale_property WHERE category='Trending' AND accept_status='Active' ORDER BY property_id DESC ";
        return $this->objConnect->GetData($sql);
    }
    //for Getting propery on the base of File status.
    public function GetpropertyByFile()
    {
            $sql="select * from sale_property WHERE type='File' AND accept_status='Active' ORDER BY property_id DESC ";
        return $this->objConnect->GetData($sql);
    }
    public function GetallpropertyByFile()
    {
            $sql="select * from sale_property WHERE type='File' AND accept_status='Active' ORDER BY property_id DESC  ";
        return $this->objConnect->GetData($sql);
    }

        public function getimages($propertyid)
    {
        $sql="select images from images_property  where property_id=$propertyid";
        return $this->objConnect->GetData($sql);


    }
    // for getting images of property
    public function getimg($propertyid)
    {
        $sql="select images from images_property  where property_id=$propertyid  limit 0,3";
        return $this->objConnect->GetData($sql);


    }

    }

so what should be the url in ajax how I pass value in ajax now, right now i am passing like this :

 $.ajax({
            url: 'http://localhost/test/process.php',
            data: { vall : parent },

Regards

Harris Khan
  • 247
  • 10
  • 26
  • If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Feb 20 '17 at 21:30

1 Answers1

0

You don't need any change from the client side. However, to obtain the value in your class, this should be the code for your new process.php file.

class location {

    public function getLocation($e) {

        global $sql;

        $sql = "SELECT * FROM tab2 WHERE name = '" . $e . "'";
        return $this->objConnect->GetData($sql);
    }

}

if (isset($_GET['val1'])) {

    $location = new location();
    $location = $location->getLocation($_GET['val1']);

}
Areeb
  • 554
  • 4
  • 13
  • but i have too many functions in my process.php, I donot want to use if (isset($_GET['val1'])) { $location = new location(); $location = $location->getLocation($_GET['val1']); } is there any other way?? – Harris Khan Feb 17 '17 at 06:33
  • Can you please edit your original post and put more of your code there so that we can check it? – Areeb Feb 17 '17 at 06:34
  • Odd that you don't want to initialize the class. In that class, you can make getLocation() a static class, you will be able to access it without initializing the class. – Areeb Feb 17 '17 at 06:41