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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:47:34+00:00 2026-06-09T02:47:34+00:00

-Issue Still Unresolved- I’m trying to call a database, put all the rows of

  • 0

-Issue Still Unresolved-

I’m trying to call a database, put all the rows of a table in an array, pass that table to my JS as json data, and then use that data as parameters for a function.

When I run the script nothing happens. I don’t get any errors in the console, the rest of the script loads normally. I’m pretty new to mySQL and PHP, what am I doing wrong here? I suspect that I goofed up the php somehow.

  • XAMPP server, being tested on my desktop
  • all linked files are in the same directory
  • There are no visible errors displayed anywhere. As far as I can tell, the script doesn’t even try to load the PHP to begin with, but also doesn’t display an error in firebug’s console

Attempted:

  • Renaming the table without spaces
  • placing the for loop inside the callback function
  • amending php errors

Here’s the updated JS I’m using:

    this.taskMenu = function()
    {
        var table = [];
        $.getJSON("taskMaster.php", {"table" : "firstlist"},
            function(data)
            {
                table.push(data);

                for(i=0; i<table.length; i++)
                {
                    var taskId = table[i].taskName.replace(/\s+/g,"") + i;
                    formatTask("interface",taskId,table[i].taskName,table[i].taskDescription,table[i].taskComplete);
                }

            });
     }

and here’s the updated PHP:

error_reporting(E_ALL); ini_set('display_errors','On');
$con = mysql_connect("localhost", "root", "m3648y73");
if (!$con){die('Could not connect: ' . mysql_error());};
mysql_select_db("tasklistdb", $con);

$table = $_GET['table'];

$sql = mysql_query("SELECT taskName, taskId, taskDescription, taskComplete FROM `".$table."`");
$listTasks = array();

while ($row_user = mysql_fetch_assoc($sql))
    $listTasks[] = $row_user;

echo json_encode($listTasks);

mysql_close($con);

Am I linking to the DB correctly?

  • 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-09T02:47:36+00:00Added an answer on June 9, 2026 at 2:47 am

    getJSON is asynchronous call. So before it could fetch values from PHP and execute the callback function, it moves to the for loop and here table is empty.

    Solution: shift your for loop inside the callback function

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

Sidebar

Related Questions

I have an issue in that a Symfony2 form can pass validation but still
Heyy can somebody help me ? i have this issue that still do know
I've seen the post that deal with this issue but I still can't solve
What I am asking is similar to this issue , which is still unresolved.
That's an issue I still don't understand. Sometimes I have to write: NSString* myVariable;
I have been through numerous similar questions on this forum but my issue still
I've read a couple of posts on this issue but still can't seem to
I have read a lot about this issue but mine still seems to be
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds
Read about the issue in this stackoverflow question . Still have the same issue

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.