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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:28:23+00:00 2026-06-01T13:28:23+00:00

Teaching myself the flow of data from mySQL -> PHP -> JSON / Javascript

  • 0

Teaching myself the flow of data from mySQL -> PHP -> JSON / Javascript and kind of stuck at this point. All I want to do is iterate through the external JSON data and put them into an unordered list. Ive tried to edit the example given on the jQuery site to work for me but I cant figure it out. Any help is appreciated. Here is my code.

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>

<script type="text/javascript">
$.getJSON('links.json', function(json) {
// alert("JSON Data: " + json[1].pagetitle);
});

I can confirm that data is being pulled from the external JSON file by using that commented out alert.

Here is my code for creating the JSON file:

// Require Database Connection
require_once "pdo_testdb_connect.php";

// Query Database for all available links
$STH = $dbh->query('SELECT pagetitle, pagelink FROM links');

// If empty..
if ($STH == '') {
echo "There are no links available at this time.";
}

// Set Fetch Mode
$STH->setFetchMode(PDO::FETCH_ASSOC);

$allLinks = array();

// Pull all page titles and links
while($row = $STH->fetch()) {
    $allLinks[] = $row;
} 

// Encode array to JSON
$je = json_encode($allLinks);

// Write to file
$fp = fopen('links.json', 'w');
fwrite($fp, $je);
fclose($fp);
  • 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-01T13:28:25+00:00Added an answer on June 1, 2026 at 1:28 pm

    I hope this code will work for you

    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    
    <script type="text/javascript">
           $.getJSON('links.json', function(json) {
              // alert("JSON Data: " + json[1].pagetitle);
    
               $.each(json, function(i,val){
                     var li_populate = "<li>"+i+"+ val +"</li>"; 
                      $("#myul").append(li_populate);
    
                })
    
    
           });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently teaching myself Drools Expert/Flow as well as GWT. I want to use
I am teaching myself python from this site . On Chapter 3 , when
I'm teaching myself JavaScript and PHP by building an app, and I decided I
I'm teaching myself about structures in C, and am having trouble compiling this code:
I've been teaching myself C#, and I'm just learning how to use custom data
I am teaching myself jquery it seems while working on this project. I assumed
I'm teaching myself WPF and xaml by replicating existing controls and UI from AutoCAD
I'm interested in teaching myself different data structures, something I currently know very little
So I'm teaching myself Python, and I'm having an issue with lists. I want
I am currently teaching myself about various data strutures and am a little frustrated

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.