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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:06:58+00:00 2026-05-23T06:06:58+00:00

I got code snippet from this site, which I used as shown below $data

  • 0

I got code snippet from this site, which I used as shown below

    $data = array();

while($row = mysql_fetch_assoc($num1)) {$data['row'][] = $row;}
while($row = mysql_fetch_assoc($num2))  {$data['row2'][] = $row;}


$count = count($data['row']);
echo "<table>" ;
echo "<tr>";
echo "<td width='300' bgcolor='#99CCF5' align='Left' style='padding-left:30px'><b>Country</b></td>" ;
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 1</b></td>";
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 2</b></td>";
echo "</tr>";
for($i=0;$i<=$count;$i++)
{

        if(($i % 2) == 1)
        {
            echo "<tr>" ;
            echo "<td align='center'>" . $data['row'][$i]['Country']."</td>";
            echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
            echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
            echo "</tr>" ;
        }else
        {
            echo "<tr>" ;
            echo "<td align='center'>" . $data['row'][$i]['Country'] ."</td>";
            echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
            echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
            echo "</tr>" ;
        }

}

echo "</table>" ;

which gives a reult like below

image1 http://img4.pixa.us/8ba/19338641.jpg

where the correct result should be like this

image2 http://img4.pixa.us/c1d/19338642.jpg

that is if any value in a column is empty the next adjucent value gets that position. How can I make this correct? that is if any value is empty that column must be empty.

please help and 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-05-23T06:06:59+00:00Added an answer on May 23, 2026 at 6:06 am

    You have to gather the data for each country. Your approach in the question messes up the listing since the keys for the array are not in sync. Let’s sync your rows by ‘Country’:

    $data = array();
    while($row = mysql_fetch_assoc($num1))
    {
        $c = $row['Country'];
        if (!isset($data[$c]))
        {
            $data[$c] = array('Country' => $c);
        }
        $data[$c]['MidEstimate1'] = $row['MidEstimate'];
    }
    while($row = mysql_fetch_assoc($num2))
    {
        $c = $row['Country'];
        if (!isset($data[$c]))
        {
            $data[$c] = array('Country' => $c);
        }
        $data[$c]['MidEstimate2'] = $row['MidEstimate'];
    }
    

    Now you have a row in your array for every Country, with their data from each query.

    $i = 0;
    foreach ($data as $row)
    {
        echo ($i % 2) ? "<tr class='odd'>" : "<tr class='even'>" ;
        echo "<td align='center'>" . $row['Country']."</td>";
        echo "<td align='center'>" . $row['MidEstimate1']."</td>";
        echo "<td align='center'>" . $row['MidEstimate2']."</td>";
        echo "</tr>" ;
    }
    

    Note: this only works in ‘Country’ field is present in both SQL query.

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

Sidebar

Related Questions

I am using the code template from Microsoft at this site with this snippet
The following code snippet prints the Pascals triangle,I have got this snippet from the
Here is a code snippet from DirectShowNet library, used to open a video file:
I've got this code snippet, and I'm wondering why the results of the first
this is a snippet from my code: $("#myid").append($("p:contains('text')").closest("div").clone()); I tried to get the first
While finding answer for this query with writing test code, I got to know
I started with this code snippet, which, by my understanding, is essentially a class-factory
I've got this code: rs1 = getResults(sSQL1) rs2 = getResults(sSQL2) rs1 and rs2 and
I have got some code to load an assembly and get all types, which
I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd

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.