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

  • Home
  • SEARCH
  • 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 8989663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:19:00+00:00 2026-06-15T22:19:00+00:00

I am a beginner in PHP programing.i have a code and i need to

  • 0

I am a beginner in PHP programing.i have a code and i need to get the first 3 datas in the first table and all the datas in the next table.the data is coming from db as json.

The following is my php file

<?php 
    $host = "localhost"; 
    $user = "root"; 
    $pass = ""; 
    $database = "TMS_Sample"; 

    $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
    mysql_select_db($database, $linkID) or die("Could not find database."); 


    $result = mysql_query("SELECT * FROM Completed_Training");
    while ($row = mysql_fetch_assoc($result)) {
        $array[] = $row;
    }
    echo json_encode($array);
?> 

I get the following json as result:

[{"Date":"2012-12- 04","Topic":"Collections","Trainer":"Prabhakaran.G","Status":"Invitation Sent"},{"Date":"2012-12-12","Topic":"Collections","Trainer":"Prabhakaran.G","Status":"Invitation Sent"},{"Date":"2012-12-07","Topic":"ffb","Trainer":"vcvxcv","Status":"cvxcv"},{"Date":"2012-12-08","Topic":"xcv","Trainer":"cvxcv","Status":"vxcv"},{"Date":"2012-12-09","Topic":"cvxcv","Trainer":"cvxcv","Status":"cvxcvxc"},{"Date":"2012-12-10","Topic":"xcv","Trainer":"vxcvxc","Status":"vxcv"},{"Date":"2012-12-11","Topic":"vv","Trainer":"vv","Status":"vxcv"},{"Date":"2012-12-12","Topic":"vv","Trainer":"vcv","Status":"cvxcv"},{"Date":"2012-12-13","Topic":"vv","Trainer":"cvxcv","Status":"cvv"},{"Date":"2012-12-14","Topic":"vxcv","Trainer":"vccv","Status":"xcvcv"},{"Date":"2012-12-14","Topic":"vcxvxc","Trainer":"cvxcv","Status":"cvxcv"},{"Date":"2012-12-15","Topic":"cvxcv","Trainer":"xcvxcv","Status":"xcvxcv"},{"Date":"2012-12-16","Topic":"sdasd","Trainer":"sdasd","Status":"dscxzc"},{"Date":"2012-12-16","Topic":"scxzcxzc","Trainer":"sdfscxzc","Status":"sadffcvzxc"},{"Date":"2012-12-17","Topic":"fxzcvxzc","Trainer":"zcvxzcz","Status":"xzcxzcxzcxz"},{"Date":"2012-12-18","Topic":"xzceafsdfv","Trainer":"vxvxv","Status":"xgsdfgvsd"},{"Date":"2012-12-12","Topic":"xcdvxvxcv","Trainer":"vxzdgvgSv","Status":"gbvsgv"},{"Date":"2012-12-27","Topic":"SDgvsdv","Trainer":"sdvsdv","Status":"sdgvsdv"},{"Date":"2012-12-11","Topic":"sdvsvd","Trainer":"sdvsdv","Status":"vdv"},{"Date":"2012-12-22","Topic":"dvsdv","Trainer":"vssdv","Status":"vsdvV"}]

Now what I need is to display this json data in a html table

I have displayed all the data in 1 table. But what I need is to get the first 3 data in the first table and all the data in the next table.

This is my html code:

<!DOCTYPE HTML>
<html>
    <head>
        <script type="text/javascript" src="jquery182.js"></script>
        <script type="text/javascript" language="javascript">
            $(document).ready(function () {
                $.getJSON('CompletedTraining.php', null, function (data) {
                    var Completed_counter = 1;
                    if (data) {
                        if (Completed_counter <= 3) {
                            var table = '<table border="1">';
                            $.each(data, function (i, element) {
                                table += '<tr>';
                                table += '<td>' + element.Date + '</td>';
                                table += '<td>' + element.Topic + '</td>';
                                table += '<td>' + element.Trainer + '</td>';
                                table += '<td>' + element.Status + '</td>';
                                table += '</tr>';
                            });
                            table += '</table>';
                            $('#getname').html(table);
                        }

                        var table1 = '<table border="1">';
                        $.each(data, function (j, element1) {
                            table1 += '<tr>';
                            table1 += '<td>' + element1.Date + '</td>';
                            table1 += '<td>' + element1.Topic + '</td>';
                            table1 += '<td>' + element1.Trainer + '</td>';
                            table1 += '<td>' + element1.Status + '</td>';
                            table1 += '</tr>';
                        });
                        table1 += '</table>';
                        $('#getname1').html(table1);
                        Completed_counter = Completed_counter + 1;
                    } else {
                        alert("error");
                    }
                });
            });
        </script>
    </head>
    <body>
        <form name="index">
            <table id="getname" ></table>
            <table id="getname1" ></table>
        </form>
    </body>
</html>
  • 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-15T22:19:02+00:00Added an answer on June 15, 2026 at 10:19 pm

    i made it as simple as i can.. so that it is easy to understand..

    no need to loop the data twice… use $.each() function once.. and check for the condition inside the $.each function

    here is the fiddle..

    http://jsfiddle.net/yXB3W/4/

    updated

    another fiddle..

    http://jsfiddle.net/yXB3W/7/

    You already have data .. so you just need to check the codes from if(data)... in fiddle

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

Sidebar

Related Questions

Total beginner with PHP: I have an form based on table data that the
Over the last year I have moved from a beginner PHP developer to a
I am just a beginner in php. I have tried to write code for
I'm an beginner in php/msql, and need help to solve this problem: I have
PHP beginner working from a tutorial. I'm trying to do a simple upload from
i'm a beginner to php. i need to use php function which process some
I am a PHP beginner. I have developed a social networking website similar to
I'm a beginner PHP coder, recently I've been told I indent my code not
I am beginner php Programmer, i am creating a shopping cart application, I have
I'm a beginner at php and was searching for a solution all day long

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.