Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:19:16+00:00 2026-06-18T12:19:16+00:00

i am trying to get the data which is in array, from an SQL

  • 0

i am trying to get the data which is in array, from an SQL query to the ajax success data. Here is the code i tried,

function adminchecksub(value1){
//alert('hi');
var value1=$('#adminsid').val();
//alert(value1);
if(value1==''){
alert('Please enter a Sub id');
}
else{
//alert(value1);
 $.ajax({

                                        type: 'POST',
                                        url: root_url + '/services/services.php?method=adminsubcheck',
                                        data: {value1:value1},
                                        async: true,
                                        success: function (data) {
                                                alert(data);

                                                if (data == 1) {
                                                        alert('inside');
                                                        //window.location.assign(rdurl+"?sid="+sid);
                                                        return true;
                                                } else {
                                                        //alert('does not exist!');
                                                       //alert('outside');
                                                        return false;
                                                }

                                        }
                                });
}

now in the php method which is requested from the above ajax call, i have to get the data return by this function which is returning an array

   function adminsubcheck($sid){
$subid=$sid['value1'];
$row = array();
//echo $subid;
$query = "SELECT Sub_id,Status,Sub_type FROM Sub WHERE Sub_id=$subid";        
        //echo $query;
        //echo $subid;
        $queryresult = mysql_query($query);
        $count  = mysql_num_rows($queryresult);
         //echo $count;

         while ($r = mysql_fetch_assoc($queryresult)) {

           $row[] = $r;
        } 
        return $row;

}

here $row is returning an array as data to the ajax function, where i need to get all the items seperately. Some one help me out to get the values into the ajax call. Thanks in advance..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:19:17+00:00Added an answer on June 18, 2026 at 12:19 pm

    In your PHP file, you can return your array as a json object in the following way (notice how the PHP file echos the result to pass it back to javascript)

    ...
    $json = json_encode($row);
    echo $json
    

    Now add the following to your javascrip ajax

     $.ajax({
    
    ...
     // Whatever code you currently have
    ...
    
    }).done(function ( json ) {
    
        var data = JSON.parse(json);
    
        //Continue with javascript
    });
    

    You can handle the java script variable ‘data’ as an associative array like it was in PHP

    also, look how you populate the php variable $row and adjust the following way:

    $cnt = 0;
    while ($r = mysql_fetch_assoc($queryresult)) {
    
            $row[$cnt] = $r;
            $cnt++;
    
    } 
     $json = json_encode($row);
        echo $json;
    

    in javascript you can access your rows the following way in teh data variable:

    var value = data[0]['field_name'];
    

    in the above statement, 0 will correspond to the value of $cnt (i.e. mysql returned row number)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using php I am trying to get some data from a .csv file which
So I'm trying to get data from my sql database and sort it by
I am trying to read data (which is actually an array) in Lisp from
I am trying to get my data which is hierarchically set up with a
I am working on PostgreSQL and psycopg2. Trying to get feed data which is
I'm trying to recursively get some data using connect by, which for each row
I am trying to get data back from a PHP file assigned with GET
I'm trying to create a SQL query using PHP in which it checks to
below is my code through which I'm trying get certain values to a drop
Hi I have created an array from core-data using: NSArray* invoiceItem =[fetchedResultsController fetchedObjects]; which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.