0

I am trying to populate dropdown-list with new data by calling a PHP page which returns an array of values.

Here is my PHP page:

<?php 

if(isset($_GET['catid']))
{
    $conn =     mysql_connect("localhost","krupa4e_skyways","skyways@1347","krupa4e_skyways");

            if (!$conn)
             {
                echo "Unable to connect to DB: " . mysql_error();
                exit;
            }


            if (!mysql_select_db("krupa4e_skyways")) 
            {
                echo "Unable to select mydbname: " . mysql_error();
                exit;
            }

                     $cat=$_GET['catid'];


            $getsubcategoriesssql='select scid,sc_name from subcategories where catid='.$cat;
                            $result=mysql_Query($getsubcategoriesssql,$conn);

                            if (!$result) 
                            {
                                die('Invalid query: ' . mysql_error());
                            }


                    $output=array();

                            while($row=mysql_fetch_row($result))
                            {
                            array_push($output,$row[0],$row[1]);

                            }


echo $output;


}
?>

How can I obtain the data I need using jQuery and bind that to an array, and later to a dropdown-list?

1 Answer 1

2

You can use json_encode to print that array in PHP code as a JSON string, and in javascript you can easily parse that JSON to an object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.