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 8213057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:59:04+00:00 2026-06-07T10:59:04+00:00

How do I pass multiple returned mysql rows through json to the below jquery

  • 0

How do I pass multiple returned mysql rows through json to the below jquery script? With the code I have written so far I can’t get the jquery success callback function to execute when i pass 2 or more to it. How would I go about accomplishing this?

jQuery, Js code:

$("#projects").click(function() {
    jQuery.ajax({ type: "POST", dataType: "JSON",
        url: "<?=base_url()?>index.php/home/projectsSlider",
        json: {returned: true}, success: function(data) {
            if (data.returned === true) {
                $("#content").fadeOut(150, function() {                             
                    $(this).replaceWith(projectsSlider(data.projectId, data.projectName, data.startDate, data.finishedDate, data.projectDesc, data.createdFor, data.contributors, data.screenshotURI, data.websiteURL), function() {
                        $(this).fadeIn(150);
                    });
                });
            }
        }
    });
});

Php code:

function projectsSlider() {
    $query  = $this->db->query("SELECT * FROM projects ORDER BY idprojects DESC");
    foreach ($query->result() as $row) {
        $projectId = $row->projectId;
        $projectName = $row->projectName;
        $startDate = $row->startDate;
        $finishedDate = $row->finishedDate;
        $createdFor = $row->createdFor;
        $contributors = $row->contributors;
        $projectDesc = $row->projectDesc;
        echo json_encode(array('returned' => true,
            'projectId' => $projectId,
            'projectName' => $projectName,
            'startDate' => $startDate,
            'finishedDate' => $finishedDate,
            'projectDesc' => $projectDesc,
            'createdFor' => $createdFor,
            'contributors' => $contributors));
    }
    $query1 = $this->db->query("SELECT * FROM screenshots s WHERE s.projectId = '{$projectId}' ORDER BY s.idscreenshot DESC");
    foreach ($query1->result() as $row2) {
        $screenshotURI = $row2->screenshotURI;
        $websiteURL = $row->websiteURL;
        echo json_encode(array('screenshotURI' => $screenshotURI,'websiteURL' => $websiteURL));
    }
}
  • 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-07T10:59:06+00:00Added an answer on June 7, 2026 at 10:59 am

    You are echoing two different JSON strings. That will not a be a valid JSON. Hence (although I have not tested it), the ajax call will fail.

    I suggest you merge the two JSONs and return just one valid JSON from the “projectsSlider()” function.
    Like so:

    $projectArray = $this->getProjectsRowSet();
    $screenshotsArray = $this->getScreenshotsRowSet();
    $combinedArray = array_merge(array("Projects" =>$projectArray),array("Screenshots" =>$screenshotsArray));
    echo json_encode($combinedArray);
    

    Then access each of the rowsets from within the ajax callback method by using “data.Projects” and “data.Screenshots”.
    Like so:

    $("#resultProjects").html(JSON.stringify(data.Projects));
    $("#resultScreenshots").html(JSON.stringify(data.Screenshots));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass multiple rows to a stored procedure. Can I use a
Can i pass multiple index fields in a Querparser in Lucene? I have done
How to pass multiple checkboxes using jQuery ajax post this is the ajax function
I can pass multiple parameters and at last one block parameter to method. But
I have a CheckBoxList where users can select multiple items from the list. I
I'm trying to pass multiple checkboxes with different values to a PHP script that
Can anyone explain to me how to pass multiple values into a parameter or
I want to pass multiple filenames (7 to 10) to a shell script from
I have an issue where I need to pass multiple criteria for a single
How I Can pass multiple values in a single parameter to a stored procedure

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.